我有一个html contols数据表,在该数据表中有一个名为Delete的链接。当我点击删除时我需要删除该项。
行动链接
@Html.ActionLink("Delete", "ProductCategory", new { id = item.CategoryId })
在我的控制器中,我要删除该项,但是这里的问题是无法返回视图,因为没有任何删除产品的视图。因为该链接的数据表在另一个视图中
public ActionResult DeleteProduct(int id) <-- Id correct here
{
return View(_pc.DeleteProduct(id));
}
实际上删除已完成我需要将其重定向到索引视图。
答案 0 :(得分:1)
而不是
return View(_pc.DeleteProduct(id));
使用此
_pc.DeleteProduct(id);
return RedirectToAction("Index", "ProductCategory");
答案 1 :(得分:1)
在ActionLink中,第二个参数是Action的名称。
@Html.ActionLink("Delete", "DeleteProduct", new { id = item.CategoryId })
如果索引位于同一个控制器中:
public ActionResult DeleteProduct(int id)
{
_pc.DeleteProduct(id);
return RedirectToAction("Index");
}