Index.cshtml:
<div class="search-ctn">
@{ Html.RenderAction(MVC.Home.Search()); }
</div>
Search.cshtml:
@model ViewModels.SearchVM
@using (Ajax.BeginForm(MVC.Home.Search(), new AjaxOptions { UpdateTargetId = "idx-list-ctn", InsertionMode = InsertionMode.Replace }, new { @id = "sch-frm" }))
{
@Html.AntiForgeryToken()
@Html.TextBoxFor(m => m.Service)
@Html.ValidationMessageFor(m => m.Service)
}
MVC.Home.Search行动:
[HttpPost, ValidateAntiForgeryToken]
public virtual PartialViewResult Search(SearchVM partnerSearch)
{
// Search made here
}
视图模型:
public class SearchVM
{
[Required]
public string Service { get; set; }
}
库:
jquery-2.1.3.js
jquery.unobtrusive-ajax.js (v3.2.3)
jquery.validate.js (v1.13.1)
jquery.validate.unobtrusive.js (v3.2.3)
在使用jquery-1.10.2.js的旧项目中,我正在激活表单的验证,如下所示:
$.validator.unobtrusive.addValidation("#sch-frm");
它工作正常,但现在它提交的表单忽略了验证。