日期:2014-05-16  浏览次数:20599 次

MVC绑定多个实体时,验证信息为什么不显示?
单绑定一个实体是没有问题,但绑定多个的时候,错误验证信息就不显示,但还是起作用,怎么样才能让错误信息显示?

@model MvcApplication.Models.ClientRegister

@{
    ViewBag.Title = "注册";
}



@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>ClientRegister</legend>
          <p>提示:(带 * 标志的为必填项)</p><br />
        <div class="editor-label">
            用户名*:
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(m => m.RegisterModel.UserName)
            @Html.ValidationMessageFor(m => m.RegisterModel.UserName)
        </div>
        <div class="editor-label">
            密码*:
        </div>
        <div>
            @Html.PasswordFor(m => m.RegisterModel.Password)
            @Html.ValidationMessageFor(m=>m.RegisterModel.Password)
        </div>
        <div class="editor-label">
             确认密码*:
        </div>
        <div>
            @Html.PasswordFor(m => m.RegisterModel.ConfirmPassword)
            @Html.ValidationMessageFor(m => m.RegisterModel.ConfirmPassword)
        </div>
          <div class="editor-label">
            @Html.LabelFor(model => model.FreeTryModel.姓名)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.FreeTryModel.姓名)
            @Html.ValidationMessageFor(model => model.FreeTryModel.姓名)
        </div>
        <div class="editor-label">
            联系电话:
        </div>
        <div>
           @Html.TextBoxFor(m => m.FreeTryModel.联系电话)
         &