Since, Ajax.BeginForm is just a wrapper around jQuery.ajax() call, is there a way to set the dataType property on the underlying ajax() object? In particular I want to set dataType="json" so that it can handle json responses.
Thanks, Roman
Since, Ajax.BeginForm is just a wrapper around jQuery.ajax() call, is there a way to set the dataType property on the underlying ajax() object? In particular I want to set dataType="json" so that it can handle json responses.
Thanks, Roman
It seems that it can (jQuery 1.5.1):
<script type="text/javascript">
function success(result) {
alert(result.Bar);
}
</script>
@using (Ajax.BeginForm("Foo", new AjaxOptions { OnSuccess = "success" }))
{
<input type="submit" value="OK" />
}
and the action would return JSON:
[HttpPost]
public ActionResult Foo()
{
return Json(new { Bar = "baz" });
}