Ajax.BeginForm和通过自定义AJAX处理Html.BeginForm之间的区别

时间:2014-06-23 09:15:04

标签: jquery ajax asp.net-mvc-3

我只想知道以下代码之间的确切区别。

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;
});
});

0 个答案:

没有答案