Asp.net-Mvc-3

如何製作帶有復選框列的 MVC 3 Webgrid?

  • September 11, 2017

下面的程式碼將在其中一個 Web 網格列中插入一個操作連結。

   @{
   View.Title = "Index";
   Layout = "~/Views/Shared/_Layout.cshtml";

   var usersGrid = new WebGrid(source: Model,
       rowsPerPage: 40);
}
@usersGrid.GetHtml(
       tableStyle: "grid",
       headerStyle: "head",
       alternatingRowStyle: "alt",
               columns: usersGrid.Columns(
                   usersGrid.Column(format: (item) => 
                        Html.ActionLink("Edit", "Edit", new { id = item.Id})),
                   usersGrid.Column("Surname")
       )
   )

但如果我用那條線換這個:

               usersGrid.Column(format: (item) => Html.CheckBox(item.Id)),

我收到此錯誤:

錯誤 4 ‘System.Web.Helpers.WebGrid.Column(string, string, System.Func, string, bool)’ 的最佳重載方法匹配有一些無效參數。

我不太明白兩者之間的區別..為什麼一個有效而另一個錯誤?

最終目標是能夠勾選多個複選框,然後發送以列印他們的資訊。

這最終對我有用。

usersGrid.Column(header: "Print?", format: @<text><input name="Prints" 
     type="checkbox" value="@item.ID" /></text>),

必須感謝尼克哈里斯,答案在他的部落格評論中找到:http: //www.nickharris.net/2010/10/a-first-look-at-the-asp-net-mvc-3-網路網格/

這對我有用:

grid.Column("SiparisNo", "Seç", format: (item) => Html.CheckBox(String.Format("Secili_{0}", (int)item.SiparisNo), false, new { @style = "width:60px;" }))

引用自:https://stackoverflow.com/questions/4306683