在ASP.NETMVC 3 Razor中使用Ajax.BeginForm是否有教程或代码示例使用Ajax.BeginForm在ASP.NETMVC 3中,是否存在不引人注目的验证和Ajax?对于MVC 3来说,这是一个难以捉摸的话题,而且我似乎无法使我的表单正常工作。它将执行Ajax提交,但忽略验证错误。
3 回答
慕工程0101907
TA贡献1887条经验 获得超5个赞
<div id="target"> @using (Ajax.BeginForm("MyAction", "MyController", new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = "target" })) { <!-- whatever --> } </div>
缥缈止盈
TA贡献2041条经验 获得超4个赞
var form = $(this);
$(document).on("submit", "form", function (event) { var form = $(this); if (form.valid()) { $.ajax({ url: form.action, // Not available to 'form' variable type: form.method, // Not available to 'form' variable data: form.serialize(), success: function (html) { // Do something with the returned html. } }); } event.preventDefault();});
$.ajax({ url: this.action, type: this.method, data: $(this).serialize(), success: function (html) { // Do something with the returned html. }});
添加回答
举报
0/150
提交
取消