creating partial view in asp.net 5 code example
Example 1: asp net core mvc partial view
<partial name="_PartialName" />
Example 2: mvc asp.net partial view from js
<div id="containerId"></div>
$.ajax({
type: "Get",
url: '<Your url>/GetView',
data: mydata,
contentType: "application/text; charset=utf-8",
dataType: "text",
success: function (data, status) {
$('#containerId').append(data);
},
error: function (err) {
console.log(err);
}
});
[HttpGet]
public ActionResult GetView(string obj)
{
try
{
MyModel model = (new JavaScriptSerializer()).Deserialize<MyModel>(obj);
return View("<Your View name>", obj);
}
catch (Exception ex)
{
return Json(ex.Message, JsonRequestBehavior.AllowGet);
}
}
Example 3: partial MVC
<partial name="ThenName" model="object" />
Example 4: asp.net mvc render multiple partial views
@{
int loopThisManyTimes = 10;
for (int i = 0; i < loopThisManyTimes; i++)
{
MyModel model = new MyModel();
Html.RenderPartial("<Your view name>", model);
}
}
$.ajax({
type: "POST",
url: '<Your URL>',
contentType: "application/text; charset=utf-8",
dataType: "text",
success: function (data) {
$("<Your container id>").html(data);
},
error: function (errData) {
$("<Your container id>").html(errData);
}
});