Rendering Partial Views using ajax Rendering Partial Views using ajax ajax ajax

Rendering Partial Views using ajax


If you want to load the page and then load the partial view via ajax you could create an ActionMethod that does something like:

public ActionResult Create(){     var model = new MyModel();     if (Request.IsAjaxRequest())     {          return PartialView( "_Partial", model.PartialModel );     }     else     {          return View( model );     } }

and then in your page do something like:

$(function(){    $(document).ajaxStart(function () {        //show a progress modal of your choosing        showProgressModal('loading');    });    $(document).ajaxStop(function () {        //hide it        hideProgressModal();    });    $.ajax({          url: '/controller/create',          dataType: 'html',          success: function(data) {             $('#myPartialContainer').html(data);          }    });});


Controller

public ActionResult GetModule(string partialName){    return PartialView("~/Views/Shared/"+partialName);}

on the Default Page (using jquery ajax operation)

<div id='mod1'>Loading...</div><script type="text/javascript">            $("#mod1").load("/ControllerName/GetModule?partialName=test1");         </script>


You can render it in the initial page by writing @Html.Partial(...).