开发者

asp.net mvc json 2 times post to the controller

开发者 https://www.devze.com 2023-01-01 13:59 出处:网络
function onTestComplete(content) { var url = \'<%= Url.Action(\"JsonTest\",\"Organizat开发者_开发知识库ion\") %>\';
function onTestComplete(content) {
    var url = '<%= Url.Action("JsonTest","Organizat开发者_开发知识库ion") %>';
    $.post(url, null, function(data) {
        alert(data["name"]);
        alert(data["ee"]);  
    });
}

<% using (Ajax.BeginForm("JsonTest", new AjaxOptions() { HttpMethod = "POST",
     OnComplete = "onTestComplete" }))

{ %>
    <%= Html.TextBox("name") %><br />
    <input type="submit" />
<% } %>

controller:`

[HttpPost]
public ActionResult JsonTest() {
 var data = new {
  name = "TestName", ee = "aaa"
 };
 return Json(data);
}

Due to some reason When I click on the button (My Break point is in the controller jsontest method) The jsontest is called twice(that's the real problem).I want to call it once as usual,using Ajax.BeginForm( "", new AjaxOptions { HttpMethod = "POST", OnComplete = "onTestComplete" })) I am able to call it once but it doesn't post the values to the controller.


It's being called twice because you're calling it twice - once by Ajax.BeginForm and once in onTestComplete.

The controller doesn't get any values because it doesn't take any parameters.

0

精彩评论

暂无评论...
验证码 换一张
取 消