我一直在将我的网格从标准表重写为 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>)
)
)
}
试试这个(这应该在你的里面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>)
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句