我们如何在mvc4中的wegrid上插入更新删除操作?

时间:2014-01-24 06:07:49

标签: asp.net-mvc-4 c#-4.0

我想在MVC4中的WebGrid上实现插入,更新,删除操作。我怎么能这样做?

这是我的网格代码

@model IEnumerable<MVC24Jan.UserTable>

@{
    ViewBag.Title = "ShowRecord";
    WebGrid grid = new WebGrid(Model);
}

<h2>ShowRecord</h2>

<div>
@grid.GetHtml(
    tableStyle: "webgrid",
    headerStyle: "head",
    alternatingRowStyle: "alt",
    columns:grid.Columns(
            grid.Column("UserId"),
            grid.Column("UserName"),
            grid.Column("Address")
            )

        )
</div>

这是我的控制器代码

public ActionResult ShowRecord()
    {
       DBLayer db = new DBLayer();
       var usertablList= db.GetAllRecord();
       return View(usertablList);
    }

 public List<UserTable> GetAllRecord()
    {
        List<UserTable> userTable = new List<UserTable>();
        userTable = entity.UserTables.ToList();
        return userTable;
    }

如何在此网格上实施插入,更新和删除操作?

1 个答案:

答案 0 :(得分:1)

我建议你阅读文章:http://www.dotnet-tricks.com/Tutorial/mvc/E2S9150113-Enhancing-WebGrid-with-Insert-Update-and-Delete-Operations.html
几个月前它帮助我解决了类似的问题