2012-01-12 55 views
0

我想從列表視圖中刪除Ajax,當我按下按鈕「刪除(Ajax)」時,它沒有在控制器方法中輸入,它會生成錯誤:在mvc3中刪除一行與ajax

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

任何想法?

//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

確保您參考以下文件:

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