我正在尝试使用列表视图中的Ajax进行删除,当我按下“Delete(Ajax)”按钮时它不会进入控制器方法,它会生成错误:
无法找到资源。描述:HTTP 404.资源你 正在寻找(或其中一个依赖)可能已被删除, 更改名称,或暂时不可用。请查阅 以下URL并确保拼写正确。 请求的网址:/ Idea / DeleteAjax / 30
有什么想法吗?
//controller
[HttpPost]
public ActionResult DeleteAjax(int id)
{
IdeeRepository ideeRepo = new IdeeRepository();
WIKIIDEE idee = new WIKIIDEE();
idee = ideeRepo.GetIdeeByID(id);
ViewModels.AjaxResponseVM ajaxVM;
try
{
ideeRepo.DeleteIdea(idee);
ideeRepo.SaveIdea();
ajaxVM = new ViewModels.AjaxResponseVM(Convert.ToInt32(idee.ID), "Idee eliminato con successo!");
}
catch
{
ajaxVM = new ViewModels.AjaxResponseVM(-1, "Error!");
}
return Json(ajaxVM);
}
//查看
@Ajax.ActionLink("Elimina Idea(Ajax)", "DeleteAjax", "Idea", new { id = ViewBag.Ideas[i].ID }, new AjaxOptions { Confirm = "Are you sure!", OnSuccess = "DeleteResponse", HttpMethod = "POST" })
答案 0 :(得分:0)
确保您引用以下文件:
<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>