0

I have the following two action links on a page:

@Html.ActionLink("User List","list");
@Html.ActionLink("Admin List","admin");

On their click I want to show/hide a partial view using jQuery. Help me with solution for this.

1
  • 2
    You'd better use ajax for this Commented Oct 8, 2012 at 6:25

2 Answers 2

4

You could use the Ajax.ActionLink helper instead:

@Ajax.ActionLink("User List","list", new AjaxOptions { UpdateTargetId = "someDiv" });
@Ajax.ActionLink("Admin List","admin", new AjaxOptions { UpdateTargetId = "someDiv" });

This assumes that the list and admin actions return partial views:

public ActionResult List()
{
    return PartialView();
}

and the result of this partial view will be injected into a DOM element with id="someDiv". Also for this to work don't forget to include the jquery.unobtrusive-ajax.js script to your page

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
Sign up to request clarification or add additional context in comments.

4 Comments

This is not working the div is not showing the patial view rather and also the UI is getting distorted after that.
Did you try debugging your controller code? Is the corresponding action being hit? Also you might use FireBug to analyze the AJAX request and the exact request/response sent over the wire as well as any possible errors.
Thanks it worked. This is something nice and a good and shorter solution to0 the problem. Thanku
If I redirect to some other page and then come back to the page where these two link buttons are then that links become disable and are not working. If I refresh the page then it is working. Why?
0
<div id="test"></div>

@Ajax.ActionLink("User List","list", new AjaxOptions{ UpdateTargetId = "test" });
@Ajax.ActionLink("Admin List","admin", new AjaxOptions{ UpdateTargetId = "test" });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.