这是我的控制者:
public ActionResult MyGrid()
{
List<User> li = new List<User>();
DataSet ds = new DataSet();
Connection.Connection con = new Connection.Connection();
ds = con.mydata();
foreach (DataRow dr in ds.Tables[0].Rows)
{
li.Add(new User
{
Name=dr["Name"].ToString(),
Email= dr["Email"].ToString(),
MobileNo= dr["MobileNo"].ToString()
});
}
return View(li);
}
这是我的View(.cshtml文件)。我创建了一个Grid,并使用下面的代码在其中添加了一个按钮。
WebGrid grid = new WebGrid(Model, rowsPerPage: 5);
@grid.GetHtml(
tableStyle: "table", // applying style on grid
fillEmptyRows: true,
//show empty row when there is only one record on page to it will display all empty rows there.
headerStyle: "header", //applying style.
footerStyle: "grid-footer", //applying style.
mode: WebGridPagerModes.All, //paging to grid
firstText: "<< First",
previousText: "< Prev",
nextText: "Next >",
lastText: "Last >>",
columns: new[] // colums in grid
{
grid.Column("Name"), //the model fields to display
grid.Column("Email" ),
grid.Column("MobileNo"),
grid.Column("Action", format: @<text>
<button >Edit</button>
</text>, style: "col3Width" , canSort: false), })
我想在单击Grid中的Edit Button时执行操作。我怎么能这样做?