Jquery Ajax.BeginForm和通过自定义Ajax处理Html.BeginForm之间的区别
我只是想知道以下代码之间的确切区别 Ajax.beg通知方式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
@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。检查它会让您更清楚