[HttpGet]
public ActionResult Index()
{
if (HttpContext.Request.Headers.XRequestedWith == "XMLHttpRequest")
return PartialView("_IndexGrid", repository.GetPeople());
return View();
}
@Html.AjaxGrid(Url.Action("Index"))
@model IQueryable<Person>
@* Should only include grid declaration *@
@(Html
.Grid(Model)
.Build(columns =>
{
columns.Add(model => model.Name).Titled("Name");
columns.Add(model => model.Surname).Titled("Surname");
columns.Add(model => model.MaritalStatus).Titled("Marital status");
columns.Add(model => model.Age).Titled("Age");
columns.Add(model => model.Birthday).Titled("Birthday").Formatted("{0:d}");
columns.Add(model => model.IsWorking).Titled("Employed");
})
.Empty("No data found")
.Pageable(pager =>
{
pager.PagesToDisplay = 2;
pager.RowsPerPage = 2;
})
.Filterable()
.Sortable()
)
public class IndexModel : PageModel
{
public void OnGet()
{
}
}
public class IndexGridModel : PageModel
{
public IQueryable<Person> People { get; set; }
public void OnGet()
{
People = repository.GetPeople();
}
}
@page
@model IndexModel
@Html.AjaxGrid(Url.Page("IndexGrid"))
@page
@model IndexGridModel
@{ Layout = null; }
@* Should only include grid declaration *@
@(Html
.Grid(Model.People)
.Build(columns =>
{
columns.Add(model => model.Name).Titled("Name");
columns.Add(model => model.Surname).Titled("Surname");
columns.Add(model => model.MaritalStatus).Titled("Marital status");
columns.Add(model => model.Age).Titled("Age");
columns.Add(model => model.Birthday).Titled("Birthday").Formatted("{0:d}");
columns.Add(model => model.IsWorking).Titled("Employed");
})
.Empty("No data found")
.Pageable(pager =>
{
pager.PagesToDisplay = 2;
pager.RowsPerPage = 2;
})
.Filterable()
.Sortable()
)