我已经将我的网格从标准表重写为webgrid网格以支持分页和排序,但是我在添加"删除"柱。这是我删除的原始代码:
@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>)
)
)
}
答案 0 :(得分:0)
试试这个(这应该在你的BeginForm
)
@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> <button type="submit" name="Delete" value="@item.ProductId">Delete</button></text>)
)