Loading partial view on Ajax.Actionlink click

Posted by Anuraj on Sunday, May 4, 2014 Reading time :1 minute

.Net ASP.Net MVC HTML5 Javascript

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">
@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.

Happy Coding.

What do you think? I would like to hear your thoughts, suggestions, and questions in the comments section below.

Similar Posts

Did you like this article? Share it with your friends

Facebook Twitter Google+ LinkedIn Reddit StumbleUpon

BMC logoBuy me a coffee

Copyright © 2019 - Anuraj P. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Hosted with ❤ by GitHub