You can do it as follows:
In document.ready()
call your Action
which will return your partial view as string and then you can replace this result using replace()
in jquery:
Ajax call :
$(document).ready(function() {
$.ajax({
url: "/ControllerName/ActionName",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
$("#placeholder").replaceWith(data);
}
});
});
controller:
[HttpPost]
public JsonResult ActionName(ModelType model)
{
......
return Json((RenderRazorViewToString("PartialViewName", model)), JsonRequestBehavior.AllowGet);
}
[NonAction]
public string RenderRazorViewToString(string viewName, object model)
{
ViewData.Model = model;
using (var sw = new StringWriter())
{
var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
viewResult.View.Render(viewContext, sw);
viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
return sw.GetStringBuilder().ToString();
}
}