Asp.net mvc 3 在启用客户端验证MVC3时发生回发

Asp.net mvc 3 在启用客户端验证MVC3时发生回发,asp.net-mvc-3,validation,Asp.net Mvc 3,Validation,我已经启用了客户端验证,它确实在工作,因为我在提交表单时看到了必填字段的错误消息。尽管客户端验证已经启动,但回发也在发生。我的理解是,客户端验证应该抑制回发。有人能帮我确认一下这是预期的行为,看看这一观点是否有问题。非常感谢 这是有争议的观点 @model Intranet.ViewModels.Student.CreateStudentViewModel @{ ViewBag.Title = "Create Student"; } <h2> Create Stude

我已经启用了客户端验证,它确实在工作,因为我在提交表单时看到了必填字段的错误消息。尽管客户端验证已经启动,但回发也在发生。我的理解是,客户端验证应该抑制回发。有人能帮我确认一下这是预期的行为,看看这一观点是否有问题。非常感谢

这是有争议的观点

@model Intranet.ViewModels.Student.CreateStudentViewModel
@{
    ViewBag.Title = "Create Student";
}
<h2>
    Create Student</h2>
<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>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <table class="detailViewTable">
        <tr>
            <td>@Html.LabelFor(c=>c.Contact.Title)</td>
            <td>@Html.EditorFor(c=>c.Contact.Title)</td>
            <td>@Html.ValidationMessageFor(c=>c.Contact.Title)</td>
        </tr>
        <tr>
            <td>@Html.LabelFor(c=>c.Contact.FirstName)</td>
            <td>@Html.EditorFor(c=>c.Contact.FirstName)</td>
            <td>@Html.ValidationMessageFor(c=>c.Contact.FirstName)</td>
        </tr>
        <tr>
            <td>@Html.LabelFor(c=>c.Contact.LastName)</td>
            <td>@Html.EditorFor(c=>c.Contact.LastName)</td>
            <td>@Html.ValidationMessageFor(c=>c.Contact.LastName)</td>
        </tr>
        <tr>
            <td>@Html.LabelFor(c=>c.Contact.Phone)</td>
            <td>@Html.EditorFor(c=>c.Contact.Phone)</td>
            <td>@Html.ValidationMessageFor(c=>c.Contact.Phone)</td>
        </tr>
        <tr>
            <td>@Html.LabelFor(c=>c.Contact.AltPhone)</td>
            <td>@Html.EditorFor(c=>c.Contact.AltPhone)</td>
            <td>@Html.ValidationMessageFor(c=>c.Contact.AltPhone)</td>
        </tr>
        <tr>
            <td>@Html.LabelFor(c=>c.Contact.Email)</td>
            <td>@Html.EditorFor(c=>c.Contact.Email)</td>
            <td>@Html.ValidationMessageFor(c=>c.Contact.Email)</td>
        </tr>
        <tr>
            <td>Guardian 1</td>
            <td>@Html.DropDownListFor(c=>c.Guardian1ID, new SelectList(Model.Contacts, "ID", "FullName"))</td>
        </tr>
        <tr>
            <td>Guardian 2</td>
            <td>@Html.DropDownListFor(c=>c.Guardian2ID, new SelectList(Model.Contacts, "ID", "FullName"))</td>
        </tr>

    </table>
    <p>
        <input type="submit" value="Create" />
    </p>

}
<div>
    @Html.ActionLink("Back to List", "List")
</div>

您需要在
jquery.validate.min.js
脚本之前添加对
jquery.min.js
脚本的引用。。。这应该可以解决您的问题。@HTX9谢谢,但它已经在_layout.cshtml中被引用了
public class CreateStudentViewModel
    {
        public int ID { get; set; }
        public ContactViewModel Contact { get; set; }
        public int Guardian1ID { get; set; }
        public int Guardian2ID { get; set; }
        public List<ContactViewModel> Contacts { get; set; }  
    }
public class ContactViewModel
    {
        public int ID { get; set; }

        [Required(ErrorMessage = "Title is required")]
        public string Title { get; set; }

        [Required(ErrorMessage = "First Name is required")]
        [DisplayName("First Name")]
        public string FirstName { get; set; }

        [Required(ErrorMessage = "Last Name is required")]
        [DisplayName("Last Name")]
        public string LastName { get; set; }

        public string Phone { get; set; }

        [DisplayName("Alternate Phone")]
        public string AltPhone { get; set; }

        public string Email { get; set; }

        public string FullName
        {
            get { return string.Format("{0} {1} {2}", Title, FirstName, LastName); }
        }