2017-07-10 42 views
-1

它在localhost上正常工作,但在部署後無法工作。我使用jQuery從控制器刪除:在這裏,我使用的類型:刪除,但即使是GET,POST沒有什麼工作ajax在遠程端不能工作,但在mvc.net的localhost上工作

$("#btnDelete").click(function (e) { 
     e.preventDefault(); 
     //alert("delete button clicked"); 
     bootbox.confirm("Do you really want to delete this User", function(result) { 
      if (result) { 
       $.ajax({ 
        url: "User/DoDelete/"[email protected], 
        type:"Delete", 
        success: function() { 

         // bootbox.alert("USer "+ @Model.ID+" Deleted successFully"); 
         window.location.href = '@Url.Action("Index","User")'; 
        }, 
        error:function() { 
         bootbox.alert("Error"); 
        } 
       }); 
      } 
     }); 
    }); 

和我的控制器是

[HttpDelete] 
     public ActionResult DoDelete(int id) 
     { 
      context = new Cost(); 
      UserEmployee user = context.UserEmployees.Where(x => x.ID == id).FirstOrDefault(); 
      if (user == null) 
      { 
       return HttpNotFound(); 
      } 
      try 
      { 
       context.UserEmployees.Remove(user); 
       context.SaveChanges(); 

      } 
      catch (Exception e) 
      { 
       Console.WriteLine(e.Message); 
      } 
      return RedirectToAction("Index"); 
     } 

我不明白爲什麼它是在本地主機上工作,但不在部署方面。

+0

是應用程序設置爲應用程序在IIS或虛擬目錄中。並且,直接在默認網站下? –

+0

作爲默認網站中IIS的應用程序 –

回答

0

用途如下:

url: '@Url.Action("DoDelete","User",new RouteValueDictionary(new { id = Model.ID}))', 

或使用如下

url: '@Url.Action("DoDelete", "User", new { id = Model.ID})', 
+0

雖然這可能是正確的答案,但您不應發佈僅限代碼的答案。請解釋*爲什麼*這將糾正用戶的問題。 –

0

非常感謝你,寫如下它解決了這個問題

var newUrl='@Url.Action("DoDelete","User")?id='[email protected]; 
相關問題