2

without refresh

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 ?

3
  • you can do ajax call for it. Commented Jan 23, 2019 at 9:11
  • 1
    Which version of MVC are you using? .NET4.6 or Core? Commented 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. Hth Commented Jan 23, 2019 at 18:05

1 Answer 1

1

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.Ajax NuGet 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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.