提交表單我有代碼的看法波紋管:如何在MVC
@using (@Html.BeginForm("DeleteItem", "Test", new { id = 3 }, FormMethod.Post, new { @class = "form" }))
{
@Html.AntiForgeryToken()
<a class="submit-process" href="javascript:void(0);"><i class="fa fa-trash-o"></i> Delete</a>
}
Script代碼:
$('.submit-process').click(function() {
if (confirm('You want delete?')) {
$(this).closest("form").submit();
}
else return false;
});
和行動Controlller測試波紋管:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult DeleteItem(int id)
{
return View();
}
當我點擊提交,未找到操作DeleteItem和郵件錯誤:
因爲你沒有指定你viewName
在
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult DeleteItem(int id)
{
return view('YOUR VIEW NAME');
}
而你的榜樣這種類型的錯誤可能發生的是發生
The view 'DeleteItem' or its master was not found or no view engine supports the searched locations
是這種方法'DeleteItem'在測試控制器? –
@SmitPatel:DeleteItem是TestController中的Action –
'return View();'表示您在'TestController'中返回名爲'DeleteItem.cshtml'的視圖。如果你想返回一個不同的視圖,那麼你需要指定它的名稱 - '返回視圖(「MyOtherView」);' –