This can be done using URL Routing or ASP.NET MVC Framework.
MVC Framework only will have HTML No view state, No Page Life cycle concept, No Controls in this framework. Hence its faster and more poular. Its based on MVC architecture.
Controllers are responsible for responding to the requests.
MVC developers like to work with pure HTML. Scripts folder comes with jQuery and we can handle ajax, jQuery validations .
View and Templates renders HTML.
The archtecure is like this. Controller responsible to take data from model and pass it to the view .HTTP Request will always go to the controller.
Model brings data to the view. Model will never change.
View is concerened with presentation layer. View do not perform business calculations. View is onlt for rendering UI and responsible for viewing data. View takes data from model and put it in the right path.
Here is the code that works for the given question using MVC
Under global.asax
// Define the routes
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("Students", "Students/List/{sort}/{status}", new { controller = "User", action = "List" }); routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Students", action = "List", id = "" });
}
//Register Application_Start
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
Create a classes called student , Student details in Model Folder
Define properties for the student like id,firstname,lastname,status ,age.
public class Student
{
[Required]
public int ID { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
public string sttus { get; set; }
public int age {get;set;}
}
Then you need to create a student controller under controllers folder that is inherited from controllers class.
Define action Results in controller class
public ActionResult Index()
{
var studdetails = new StudentDetails();
var model = rstuddetails.GetModel();
return View(model);
}
Define necessary methods to getdata in StudentDetails
now to view Create a view called Students under view
For sorting the action result can be used under controller
public class StudentController : Controller
{
public ActionResult List(string sort, string status)
{
// check the parameters so SQL injection cannot happen
string sql = "select ID, First Name, Last Name, Age, Status from StudentsTable where Status = '" + status + "' order by " + id;
//or use LINQ to get the data
// make SQL call
// put result into dataset
// bind dataset to grid
}
}