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.
精彩评论