greeshma kb

greeshma kb

  • NA
  • 16
  • 3.1k

Grid.MVC in asp.net mvc

May 21 2019 12:08 AM
Unable to bind dynamic DataTable to Grid.MVC
 
I want to use Grid.MVC to create a grid (table). In this grid I want to bind to a DataTable, which is the Table I get from SELECT * FROM TABLE
 
My view looks like this:
@model DataTable @{ ViewBag.Title = "ViewTable"; } @using GridMvc.Html @using System.Data <h2>ViewTable</h2> @Html.Grid(Model.Columns.Cast<IEnumerable<DataColumn>>()).Columns(columns => { columns.Add().RenderValueAs(a => Html.ActionLink("Edit", "Index")); foreach (DataColumn item in Model.Columns) { try { columns.Add(a => item).Titled(item.ColumnName); } catch (Exception) { throw; } } })
 
This always throws the error column item already exists in the grid (at the second item).

Answers (6)