partial views code example
Example 1: change partial view based on select asp.net core
public IViewResult LoadPartial() {
return PartialView("_login");
}
$("#container").load("LoadPartial");
Example 2: mvc render partial view in layout stackoverflow
public ActionResult AdminMenu()
{
var am = _amr.GetAdminMenu();
return Json(am,JsonBehaviour.AllowGet);
}
@using (Ajax.BeginForm("AdminMenu","AdminController", null,
new AjaxOptions
{
OnSuccess = "renderSuccess",
OnFailure = "renderFailure",
OnBegin = "renderBegin"
},
new
{
id = "frmViewerAdminMenu",
name = "frmViewerAdminMenu"
})
)
{
...
<script type="text/javascript">
function renderSuccess(ajaxContext){
}
</script>
...
}
Example 3: asp net core mvc partial view
<partial name="_PartialName" />
Example 4: c# mvc return partial view
<div id="ViewHolder"><div>
$.ajax({
type: "POST",
url: '<Your path to your controller>/GetView',
contentType: "application/text; charset=utf-8",
dataType: "text",
async: false,
success: function (data) {
$('ViewHolder').html(data);
}
})
public PartialViewResult GetView()
{
MyModel myModel = new MyMyodel();
return PartialView("<Your View Name>", myModel);
}