views:

57

answers:

1
  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.

+2  A: 

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.

SLaks
ok how would i call it once without any problem
mazhar kaunain baig
Get rid of the second call in `onTestComplete`.
SLaks
passing null to the url in the post is stopping the displaying of alerts?
mazhar kaunain baig
Do you know what your code is doing?
SLaks
it is displaying alerts
mazhar kaunain baig
Why are you sending a second POST?
SLaks
ok got your point
mazhar kaunain baig
calling it on button click now thanks
mazhar kaunain baig