When I click on any page link of the partial view, that related page should be displayed in the render body part without any page refresh. How can I do that ?
-
you can do ajax call for it.Arvind Maurya– Arvind Maurya2019-01-23 09:11:34 +00:00Commented Jan 23, 2019 at 9:11
-
1Which version of MVC are you using? .NET4.6 or Core?Piotr Kula– Piotr Kula2019-01-23 09:13:32 +00:00Commented Jan 23, 2019 at 9:13
-
Realistically, it's too broad of a topic and sample code will only get you so far. Here's documentation on the topic to get you going. Doesn't matter what flavor of Asp.Net. HthEdSF– EdSF2019-01-23 18:05:48 +00:00Commented Jan 23, 2019 at 18:05
Add a comment
|
1 Answer
You can use the AJAX helper that is used in conjunction with unobtrusive ajax
You can find more information at this page
- Install
Microsoft.jQuery.Unobtrusive.AjaxNuGet package - Include the script on _Layout
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script> - You then use the HTML Helper with specific options
Code Sample
@Ajax.ActionLink("View All Student Info", "AllStudent", "Home", new AjaxOptions
{
UpdateTargetId = "divAllStudent",
OnBegin = "fnOnBegin",
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET",
LoadingElementId = "imgloader",
OnSuccess= "fnSuccess",
Confirm="Do you want to get all student info ?????"
},
new { @class = "btn btn-default" })
- Then in the controller add a specific [GET] Route (WebAPI)
Code Sample
[HttpGet]
public PartialViewResult AllStudent()
{
using (TempEntities db = new TempEntities())
{
var objAllStudent = db.StudentInfoes.ToList();
return PartialView("AllStudent", objAllStudent);
}
}
The options UpdateTargetId is the HTML ID container of where the AJAX result will put the result content. Usually you want to use Replace. You can use OnBegin and OnSuccess as Javascript methods that do things like show loaders, hide loaders, etc etc