2014-01-31 48 views
0

我的Ajax發佈不在asp.net中工作mvc4.Ajax調用不會觸及action.How要解決它嗎?在asp.net中的Ajax發佈問題mvc4

$.ajax({ 
     type: 'POST', 
     url: "http://localhost:8871/Account/Add", 
     contentType: 'application/json', 
     dataType: 'json',    
     data: JSON.stringify({ id: '2' }), 
     success: function (data) { } 

     }); 

我的控制器動作

[HttpPost] 
    public ActionResult Add(string id) 
    { 
     return View(); 
    } 
+0

沒有什麼工作,什麼錯誤,是Ajax調用擊球動作? –

+0

ajax調用不起作用 –

+0

你在控制檯中看到了什麼錯誤? –

回答

0

更改您的網址是這樣,

$.ajax({ 
    type: 'POST', 
    url: '@Url.Action("Add","Account")' , 
    contentType: 'application/json', 
    dataType: 'json',    
    data: JSON.stringify({ id: '2' }), 
    success: function (data) { } 

    });