WebGrid中的Crud

时间:2014-01-18 12:24:26

标签: asp.net-mvc webgrid

如何将删除,更新,编辑按钮放入MVC webGrid?

代码:

<div>

@{

    var grid = new WebGrid(ViewData.Model, defaultSort: "EmplID");

}

@grid.GetHtml()

</div>

控制器:

public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Precise Technology Consultants";
            var DataContext = new EmployeeAtdDataContext();
            //var EmployeeAtd = DataContext.GetAttendance_Sp();
            IEnumerable<GetAttendance_SpResult> EmployeeAtd = DataContext.GetAttendance_Sp().ToList();
            return View(EmployeeAtd);
        }

现在我想把ADD,Delete,按钮放进去吗?

1 个答案:

答案 0 :(得分:0)

我认为你正在寻找这样的东西:

@grid.GetHtml(columns: new [] {
    grid.Column("col1"),
    grid.Column("col2"),
    grid.Column(
       "",
        header: "Actions",
        format: @<text>
                @Html.ActionLink("Edit",   "Edit",   new { EmplID=item.EmplID} )
                |
                @Html.ActionLink("Delete", "Delete", new { EmplID=item.EmplID} )
               </text>
    )
})

控制器包含以下方法:

public ActionResult Edit(int EmplID)
...