【问题标题】:How to Bind List to Grid in Asp.Net MVC如何在 Asp.Net MVC 中将列表绑定到网格
【发布时间】:2015-07-31 10:12:55
【问题描述】:

我正在尝试将数据库绑定到 MVC5 应用程序中的 Grid,这是我的第一次尝试。

创建模型类和控制器。我的模型正在返回数据表。我想绑定网格中的数据。 下面是我的控制器代码,它将返回列表。

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

我可以在 @model IEnumerable 视图中添加模型

从这里我无法理解如何创建网格以及如何绑定此列表。我选择了 Razor 视图引擎。

任何机构都可以显示一些示例代码以在 MVC 中绑定网格选项谢谢

【问题讨论】:

  • 我的帖子对您​​有帮助吗?
  • @Jamie Rees:抱歉回复晚了,我可以看到网格,并且正在玩。非常感谢您的及时回复。

标签: asp.net-mvc


【解决方案1】:

看看MVC Grid它是一个救生员。

这是你将如何使用它:

@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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-30
    • 1970-01-01
    • 2011-03-04
    相关资源
    最近更新 更多