HTML表单
<form id="form_CreateAccount" method="post" action="@Url.Action("CreateAccount","Account")" autocomplete="off">
<div class="col-md-3 form-group">
<label>Account Name*</label>
<input type="text" name="AccountName" class="form-control" required/>
</div>
<div class="col-md-3 form-group">
<label>Account Type</label>
@Html.DropDownList("AccountTypeId",new SelectList(ViewBag.AccountTypes,"Id","Type"), new {@class="form-control"})
</div>
<div class="col-md-3 form-group">
<button type="submit" class="btn btn-success adjust-btn">Create</button>
</div></form>
JQuery .ajaxForm()方法:
$("#form_CreateAccount").validate();
$("#form_CreateAccount").ajaxForm({
beforeSubmit: function () {
return $("#form_CreateAccount").valid();
},
dataType: "json",
success: function (res) {
if (res.success === true) {
else {
}
}
})
这是我的控制器
public class AccountController : Controller
{
IAccountService _accountSrvc;
[HttpPost]
public JsonResult CreateAccount(Account account)
{
var res = _accountSrvc.CreateAccount(account);
return Json(new { success = res });
}
}
如果没有.ajaxForm()方法,此表单成功提交,但是当我使用.ajaxForm()提交表单时,它会给出错误404
答案 0 :(得分:0)
beforeSubmit: function () {
return $("#form_CreateAccount").valid();
}
.valid()
导致问题后的分号。