How to load grid using ajax load in asp.net
Controller code
[GridAction]
public ActionResult GetStudentInfo(string roll)
{
List<Student> lstStudent = new List<Student>();
int rollNumber = Convert.ToInt32(roll);
using (db_practiseEntities dbContext = new db_practiseEntities())
{
lstStudent = (from s in dbContext.Student
where s.Roll == rollNumber
select s).ToList();
}
return View(new GridModel<Student> { Data = lstStudent });
}
view code
@(Html.Telerik().Grid<Student>()
.Name(“gdStudentList”)
.DataKeys(keys => keys.Add(k => k.Roll))
.Columns(column =>
{
column.Bound(s => s.Id);
column.Bound(s => s.StudentName);
column.Bound(s => s.Roll);
column.Bound(s => s.DepartmentName);
column.Bound(s => s.Email);
})
.DataBinding(dbBindings => dbBindings.Ajax().Select(“GetStudentInfo”, “Home”))
)
js code
$(“#Student”).change(function () {
var params = {
roll: this.value
};
var grid = $(‘#gdStudentList’).data(“tGrid”);
grid.dataSource._data = [];
grid.ajaxRequest(params);
});