2014-09-20 1 views
0

컨트롤러로 ID 전달 시도 중 (ID가 null이 아님) 컨트롤러에서 null을 얻는다고 컨트롤러가 생각합니다.jquery ajax 데이터 전송 - ASP.Net MVC

public ActionResult Delete(string id) 
    { 
     return null; 
    } 

그리고 당신의 jQuery 코드와 HTML은 다음과 같이 말한다 - - 여기 컨트롤러

public ActionResult Delete(string id) 
     { 
... 
} 

답변

1

var url = '@Url.Action("Delete")'; 

     $.ajax({ 
      url: url, 
      async: false, 
      data: {id:clientId},// have also tried data:clientId and data:[clientId] 
      type: 'POST', 
     }); 

는 구현 간다

<script src="~/Scripts/jquery-1.8.2.min.js"></script> 
<script> 
    function submitForm() { 
     var model = new Object(); 
     model.Name = "Rami"; 

     jQuery.ajax({ 
      type: "POST", 
      url: "@Url.Action("Delete")", 
      dataType: "json", 
      contentType: "application/json; charset=utf-8", 
      data: JSON.stringify({ id: model.Name }), 
      success: function (data) { alert(data); }, 
      failure: function (errMsg) { 
       alert(errMsg); 
      } 
     }); 
    } 
</script> 

<input type="button" value="Click" onclick="submitForm()"/> 

코드를 실행

-

enter image description here

+0

고맙습니다. –