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是必须引用的。

你可能感兴趣的:(Ajax)