weixin_33709609 2012-01-12 11:58 采纳率: 0%
浏览 72

在MVC3中使用Ajax删除行

I am trying to do a delete with Ajax from a list view and when I press button "Delete (Ajax)" it doesn't enter on the controller method, it generates the error:

The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. Requested URL: /Idea/DeleteAjax/30

Any ideas?

 //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);
        }

// view

@Ajax.ActionLink("Elimina Idea(Ajax)", "DeleteAjax", "Idea", new { id = ViewBag.Ideas[i].ID }, new AjaxOptions { Confirm = "Are you sure!", OnSuccess = "DeleteResponse", HttpMethod = "POST" })
  • 写回答

1条回答 默认 最新

  • 北城已荒凉 2012-03-31 13:51
    关注

    Make sure you are referencing the following files:

    <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>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘