Part 92 Ajax With Asp Net Mvc
Link for code samples used in the demo
Link for csharp, asp.net, ado.net, dotnet basics, mvc and sql server video tutorial playlists
ASP.NET AJAX enables a Web application to retrieve data from the server asynchronously and to update portions of the existing page. So these, partial page updates make web application more responsive and hence improves user experience.
In this video, let’s discus using Ajax.ActionLink helper. By the end of this video, we should be able to load either
1. All students or
2. Top 3 students or
3. Bottom 3 students
depending on the link we have clicked.
Here are the steps to achieve this
Step 1: Create and populate table tblStudents
Step 2: Create an ado.net entity datamodel using table tblStudents. Upon creating the entity model, change the name of the entity to Student. Save changes and build the solution, so that the Student entity class gets compiled.
Step 3: Add “Shared” folder (if it doesn’t already exists) in “Views” folder. Right click on “Shared” folder and add a partial view, with name = _Student.cshtml.
Step 4: Right click on the “Controllers” folder and add a controller with the following settings
1. Controller Name = HomeController
2. Template = Empty MVC controller
Step 5: Right click on the “Views” folder and add a folder with name = “Home”. Right click on the “Home” folder and add a view with Name = “Index”.
Points to remember:
b) Ajax.ActionLink() html helper has several overloaded versions. We have used the following version
ActionLink(string linkText, string actionName, AjaxOptions ajaxOptions);
First parameter : is the link text that we see on the user interface
Second parameter : is the name of the action method that needs to be invoked, when the link is cicked.
Third parameter : is the ajaxOptions object.