私は MVC と Javascript にかなり慣れていません。削除アクションを機能させようとしています。確認のためにJavascript関数を備えたActionLinkを使用しています。JAVascript の確認が機能しません。[キャンセル] を押しても削除アクションが実行されます。さらに、アクションに [HttpDelete] 動詞を使用できないようです: Delete アクションに 2 つのパラメーターを渡す必要がありますが、アクション リンクに @Html.HttpMethodOverride(Http.Delete) を適用した後、URL を検索します。パラメーターは 1 つだけです: id.
これが私のコードです:アクションリンク
@Html.HttpMethodOverride(HttpVerbs.Delete)
@Html.ActionLink(
"Delete",
"Delete",
new {id=notification.Id, typeId=notification.TypeId},
new {onclick="confirmDeleteAction()"})
function confirmDeleteAction() {
return confirm('Are you sure you want to delete the notification ?');
}
削除アクション:
[HttpDelete]
public ActionResult Delete(int id, int typeId)
{
Service.DeleteNotification(id, typeId);
NewIndexViewModel model = Service.GetNewIndexViewModel();
return View("Index", model);
}