asp.net mvc json 2 times post to the controller

Posted by mazhar kaunain baig on Stack Overflow See other posts from Stack Overflow or by mazhar kaunain baig
Published on 2010-06-01T13:49:10Z Indexed on 2010/06/01 13:53 UTC
Read the original article Hit count: 442

Filed under:
|
|
|
|
  function onTestComplete(content) {
        var url = '<%= Url.Action("JsonTest","Organization") %>';
         $.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.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about JavaScript