如何在mvc 5中的webgrid中添加复选框

时间:2014-12-16 06:51:04

标签: asp.net-mvc model-view-controller asp.net-mvc-5

我想在我的webgrid中添加复选框,所以任何人都可以告诉我该怎么做?并告诉我如何选择所有复选框并删除它们。这是我的代码: -

@{
  var grid = new WebGrid(
    Model, rowsPerPage: 5,
    defaultSort: "CatagoryId",
    columnNames: new[] { "Category_Name", "Parent_Category_ID", "Category_Desc", "IsGenderApplicable", "IsAgeApplicable", "IsActive" }
  );    
}
@grid.GetHtml(
  fillEmptyRows: false,
  mode: WebGridPagerModes.All,

  columns:grid.Columns(
    grid.Column("Category_Name", header: "Catagory Name"),
    grid.Column("Parent_Category_ID", header: "Parant CatID"),
    grid.Column("Category_Desc", header: "Description"),
    grid.Column("IsGenderApplicable", header: "Gender Application"),
    grid.Column("IsAgeApplicable", header:"Age Application"),
    grid.Column("IsActive", header: "Active")
  )
)

1 个答案:

答案 0 :(得分:1)

添加一个复选框:

   grid.Column(format: @<text><input name="chkbox" 
          type="checkbox" value="some value" /></text>),

您的第二个问题:如何选择所有复选框?

请参阅此博客:http://www.codeproject.com/Questions/273164/mvc-checkbox-checked-rows-in-the-web-grid