mvc4 ajax.beginform表单验证

@{
    Layout = null;
}
@model MvcApplication1.Models.User
@using (Ajax.BeginForm("create", "user", new AjaxOptions
{
    UpdateTargetId = "bform",
    HttpMethod = "post",
    OnSuccess = "success"
}))
{
    <div id="divForm">
        <span>@Html.LabelFor(m => m.UserName)</span> 
        <span>@Html.TextBoxFor(m => m.UserName)</span>
        <span>@Html.ValidationMessageFor(m => m.UserName)</span> 
        <span style="display:block;">
            <input type="submit" value="提交" /></span>
    </div>
    <div id="bform">
        
    </div>
}
<link type="text/css" rel="Stylesheet" href="@Url.Content("~/content/site.css")" />
<script src="@Url.Content("~/Scripts/jquery-1.8.3.min.js")"type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")"type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript">
    function success(data) {
        $("#bform").html(data);
    }
</script>

引用的文件:一个是CSS,一个是jquery,其它三个JS是必须引用的。

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。