Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Ajax.BeginForm和通过自定义Ajax处理Html.BeginForm之间的区别_Jquery_Ajax_Asp.net Mvc 3 - Fatal编程技术网

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

Jquery Ajax.BeginForm和通过自定义Ajax处理Html.BeginForm之间的区别,jquery,ajax,asp.net-mvc-3,Jquery,Ajax,Asp.net Mvc 3,我只是想知道以下代码之间的确切区别 Ajax.beg通知方式 @using (Ajax.BeginForm("foo", "home", new AjaxOptions { OnSuccess = "onSuccess" })) { @Html.EditorFor(x => x.SomeProperty) <button type="submit">OK</button> } @using (Html.BeginForm("foo", "home", FormMe

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

Ajax.beg通知方式

@using (Ajax.BeginForm("foo", "home", new AjaxOptions { OnSuccess = "onSuccess" }))
{
@Html.EditorFor(x => x.SomeProperty)
<button type="submit">OK</button>
}
@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;
});
});
@使用(Ajax.BeginForm(“foo”,“home”,新的AjaxOptions{OnSuccess=“OnSuccess”}))
{
@EditorFor(x=>x.SomeProperty)
好啊
}
Html.beg通知方式

@using (Ajax.BeginForm("foo", "home", new AjaxOptions { OnSuccess = "onSuccess" }))
{
@Html.EditorFor(x => x.SomeProperty)
<button type="submit">OK</button>
}
@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;
});
});
@使用(Html.BeginForm(“foo”,“home”,FormMethod.Post,new{id=“myform”}))
{
@EditorFor(x=>x.SomeProperty)
好啊
}
$(函数(){
$('#myform')。提交(函数(){
$.ajax({
url:this.action,
类型:this.method,
数据:$(this).serialize(),
成功:功能(结果){
警报(result.Foo);
}
});
返回false;
});
});

前者更简洁,后者让您可以完全控制用于创建和处理AJAX请求的JS。检查它会让您更清楚