我只想知道以下代码之间的确切区别。
Ajax.BeginForm Way
@using (Ajax.BeginForm("foo", "home", new AjaxOptions { OnSuccess = "onSuccess" }))
{
@Html.EditorFor(x => x.SomeProperty)
<button type="submit">OK</button>
}
Html.BeginForm方式
@using (Html.BeginForm("foo", "home", FormMethod.Post, new { id = "myform" }))
{
@Html.EditorFor(x => x.SomeProperty)
<button type="submit">OK</button>
}
$(function() {
$('#myform').submit(function(){
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
success: function(result) {
alert(result.Foo);
}
});
return false;
});
});