Javascript 为什么客户端验证在我的部分视图MVC4应用程序中不起作用

Javascript 为什么客户端验证在我的部分视图MVC4应用程序中不起作用,javascript,jquery,asp.net-mvc,asp.net-mvc-4,Javascript,Jquery,Asp.net Mvc,Asp.net Mvc 4,您好,我正在创建一个mvc 4应用程序,在该应用程序中,单击登录按钮将显示一个引导模式。我的登录是一个局部视图,登录按钮位于布局局部视图中。在我的登录局部视图中,我有一个注册按钮,单击该按钮,我将显示我的注册局部视图,并在我想要的注册局部视图中为了添加客户端验证,我采用了下面的方法 web.config <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnable

您好,我正在创建一个mvc 4应用程序,在该应用程序中,单击登录按钮将显示一个引导模式。我的登录是一个局部视图,登录按钮位于布局局部视图中。在我的登录局部视图中,我有一个注册按钮,单击该按钮,我将显示我的注册局部视图,并在我想要的注册局部视图中为了添加客户端验证,我采用了下面的方法

web.config

<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />

}

像这样,我补充说。但是为什么我的客户端验证不起作用

您是在动态添加分部吗?是的,像这样,我在模态$('#modalLaunchRegister')中添加我的分部视图。单击(function(){debugger;$.ajax({type:'GET',url:'Home/Register',success:function(data){debugger;$('modalloin').modal('hide');$('modalRegisterContainer').html(数据);$('modalRegister').modal('show');},错误:函数(xhr,textStatus,errorshown){debugger;警报(xhr.statusMessage);}});});我们可以看到呈现的Html和您使用的模型吗?您需要重新分析验证器。我是mvc新手。您可以建议在哪里添加此$('form')。数据('validator',null);$.validator.unobtrusive.parse($('form'));
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script src="~/Contents/Common.js"></script>


@using System.Web.Optimization
@model BlueBusApp.Models.M_BLUEBUS_USERDETAILS

@using (Html.BeginForm(null,null,FormMethod.Post,new{id="registration"}))
{
  @Html.AntiForgeryToken()
  @Html.ValidationSummary(true)


  <div class="modal-header" style="background-color: gainsboro">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title" id="myModalLabel">Create New Account</h4>
</div>
<div class="modal-body" style="height: 300px">

    <form id="frmLogin" class="form-horizontal" role="form">
            <div class="form-group">
                <div class="editor-label">
                    @Html.LabelFor(model => model.USER_EMAIL, "Email", new { @class = "control-label"  })
                </div>
                <div class="editor-field">
                    @Html.TextBoxFor(model => model.USER_EMAIL, new { @class = "form-control", id="userModelEmail" })
                    @Html.ValidationMessageFor(model => model.USER_EMAIL)
                </div>
            </div>

            <div class="form-group">
                <div class="editor-label">
                    @Html.LabelFor(model => model.USER_PASSWORD, "Password", new { @class = "control-label" })
                </div>
                <div class="editor-field">
                    @Html.TextBoxFor(model => model.USER_PASSWORD, new { @class = "form-control inputTextBox",id="userModelPwd" })
                    @Html.ValidationMessageFor(model => model.USER_PASSWORD)
                </div>
            </div>

            <div class="form-group">
                <div class="editor-label">
                    @Html.LabelFor(model => model.USER_CONFIRMPASSWORD, "Confirm Password", new { @class = " control-label" })
                </div>
                <div class=" editor-field">
                    @Html.TextBoxFor(model => model.USER_CONFIRMPASSWORD, new { @class = "form-control",id="userModelCfmPwd" })
                    @Html.ValidationMessageFor(model => model.USER_CONFIRMPASSWORD)
                </div>
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.USER_MOBILENO, "Your Mobile No", new { @class = " control-label" })
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(model => model.USER_MOBILENO, new { @class = "form-control",id="userModelMob" })
                @Html.ValidationMessageFor(model => model.USER_MOBILENO)
            </div>

            <div class="form-group" style="margin-top: 40px; margin-left:200px; ">
                <div class="col-sm-offset-2 col-sm-10">
                    <button id="btnRegister" type="button" class="btn btn-danger">Create My Account</button>
                </div>
            </div>
    </form>

</div>
<div class="modal-footer">
    <a href="#" class="anchor-horizontal pull-left" id="modalLaunchBack">Back</a>
</div>
}