Loading partial view on Ajax.Actionlink click in ASP.NET MVC

.Net, ASP.NET, MVC 0 Comments

While working on an MVC project, I had to create few partial views and load them dynamically using Ajax. Here is the code snippet for the same.

Controller method

public ActionResult ShowMenu()
{
    return PartialView("_SimpleMenu");
}

In this I am returning the Partial View in the controller method. And here is the Razor code.

<div id="MenuContainer">
</div>
@Ajax.ActionLink("Show menu", "ShowMenu", "Home", new AjaxOptions()
{
    UpdateTargetId = "MenuContainer",
    InsertionMode = InsertionMode.Replace
})

In this I am specifying the controller action method and the DIV which will be replaced by the Partial View.

Leave a Reply

Your email address will not be published. Required fields are marked *