0

I am trying to bind database to Grid in MVC5 application, its my first attempt.

Created Model class, and Controller. My model is returning data table. and i would like to bind the data in the grid. Below is my controller code which will return list.

    List<SystemManagmentModel> fileStores = new List<SystemManagmentModel>();
    SystemManagmentModel fileStore = new SystemManagmentModel();
    fileStores.Add(fileStore);
    return View(fileStores);

I am able to add Model in the view @model IEnumerable

From here i am unable to understand how to create grid and how to bind this list.I have selected Razor view Engine.

can any body show some sample code to Bind grid options in MVC Thank you

2
  • did my post help you? Commented May 20, 2015 at 19:24
  • @Jamie Rees: sorry for late reply, i am able to see grid, and playing with that.Thank you so much for the timely response. Commented May 21, 2015 at 11:40

1 Answer 1

1

Take a look at MVC Grid it is a life saver.

This is how you would use it:

@Html.Grid(Model).Columns(columns =>
{
columns.Add(x => x.Property).Titled("name of column header").Sortable(true);

columns.Add(x => x.DateTimeProperty).Titled("Release Date").SortInitialDirection(GridSortDirection.Descending)
    .Format("{0:dd/MM/yyyy HH:mm}")
    .ThenSortByDescending(x => x.DateTimeProperty);

columns.Add(x => x.Property3).Titled("Another Prop");

columns.Add(x => x.Id)
.Titled(string.Empty)
.Encoded(false)
.Sanitized(false)
.RenderValueAs(x => @<b> @Html.ActionLink("Delete", "DeleteAction", new { id = x.Id })</b>)
    .SetWidth(100);

}).Sortable(true)
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.