我一直在将我的网格从标准表重写为webgrid表,以支持分页和排序,但是我在添加“Delete”列时遇到了问题。这是我删除的原始代码:
@using (Html.BeginForm("Delete", "Admin")
{
@Html.Hidden("ProductId", item.ProductId)
<input type="submit" class="btn btn-default btn-xs" value="Delete" />
}
我无法清楚地理解如何重写它,使其与之前在webgrid中的工作方式相同。这是我目前的表格:
@grid.Table(
tableStyle: "table table-striped table-condensed table-bordered",
columns: grid.Columns(
grid.Column(columnName:"ProductId", header: "Id"),
grid.Column(columnName: "Name", header: "Name", format: (item) =>
{
var link = Html.ActionLink((string)item.Name, "Edit", new { item.ProductId });
return link;
}),
grid.Column(columnName: "Price", header: "Price"),
grid.Column(here should be the delete button)
)
)
你能帮我一下吗?提前感谢!
编辑:我尝试的是:
grid.Column(format: (item) =>
{
using (Html.BeginForm("Delete", "Admin"))
{
string htmlString = string.Empty;
Html.Hidden("ProductId", (string)item.ProductId);
htmlString = "<input type = \"submit\" class=\"btn btn-default btn-xs\" value=\"Delete\" />";
return new HtmlString(htmlString);
}
})
然而,它似乎不起作用。
编辑2:这里是工作删除,可惜没有剃刀。
@using (Html.BeginForm("Delete", "Admin"))
{
@grid.Table(
tableStyle: "table table-striped table-condensed table-bordered",
columns: grid.Columns(
grid.Column(columnName: "ProductId", header: "Id"),
grid.Column(columnName: "Name", header: "Name", format: (item) =>
{
var link = Html.ActionLink((string)item.Name, "Edit", new { item.ProductId });
return link;
}),
grid.Column(columnName: "Price", header: "Price"),
grid.Column(columnName: "", header: "", format: @<text> <input id="ProductId", name="ProductId", type="hidden", value="@item.ProductId" /><input type="submit" class="btn btn-default btn-xs" value="Delete" /></text>)
)
)
}