如何在mvc3中删除webgrid中的记录 [英] How to delete record in webgrid in mvc3
问题描述
我在这样的控制器上创建了
public ActionResult DeleteRecordFunction(int charityID)
{
try
{
//调用删除功能删除记录
objEntities.Delete(charityID);
ViewData [deletetatus] = 1;
}
catch
{
ViewData [deletetatus] =0;
}
返回RedirectToAction(/ CharityList /);
}
我的观点是
I have created on controller like this
public ActionResult DeleteRecordFunction(int charityID)
{
try
{
//Call your delete function to delete record
objEntities.Delete(charityID);
ViewData["deletetatus"] = "1";
}
catch
{
ViewData["deletetatus"] = "0";
}
return RedirectToAction("/CharityList/");
}
and my view is
<div align="left" class="griddivshadow">
@grid.GetHtml(
tableStyle: "webgrid",
alternatingRowStyle: "alternative-row",
rowStyle: "gridrow",
headerStyle: "",
footerStyle: "foot-grid",
mode: WebGridPagerModes.All,
firstText: "<< First",
previousText: "< Previous", nextText: "Next >",
lastText: "Last >>",
columns: new[] {
grid.Column("PCharityNumber","" ,canSort: true,style: "id"),
grid.Column("PCharityName","",canSort: true,style: "name"),
grid.Column("PState","",canSort: true,style: "state"),
grid.Column("",
header: "___Edit",
style:"grid-header",
format: @<text>  <a href="@Url.Action("AddCharity", "CharityView", new { charityID = Model.PCharityId })" >
<img width="15px" alt="" height="15px" src="../../Content/Images/Editfor.jpg" /><span
style="font-family: Verdana; font-size: small;">Edit</span></a>
</text>
),
grid.Column("",
header: "___Delete",
style:"grid-header",
format: @<text>   <a href="@Url.Action("CharityList", "PledgeNet", new { charityID = Model.PCharityId })" >
<img id="a" width="15px" alt="" height="15px" src="../../Content/Images/cross.png" /><span
style="font-family: Verdana; font-size: small;">Delete</span></a>
</text>
)
})
</div>
但我的webgrid编辑或删除id不会传递给控制器
所以请解决这个
but my webgrid edit or delete ids are not passed to controller
so please resolve this
推荐答案
再添加一列删除如下
Add one more column Delete like below
@grid.GetHtml(columns: new [] {
... // Rest of grid columns
grid.Column(
"",
header: "Delete",
format: @<text>
@Html.ActionLink("Delete", "DeleteRecordFunction", new { charityID=item.charityID} )
</text>
)
希望这有帮助
Hope this helps
这篇关于如何在mvc3中删除webgrid中的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!