MVC3/Razor Client Validation Not firing

I am trying to get client validation working in MVC3 using data annotations. I have looked at similar posts including this MVC3 Client side validation not working for the answer.

I'm using an EF data model. I created a partial class like this for my validations.

[MetadataType(typeof(Post_Validation))]
public partial class Post
{

}

public class Post_Validation
{
    [Required(ErrorMessage = "Title is required")]
    [StringLength(5, ErrorMessage = "Title may not be longer than 5 characters")]
    public string Title { get; set; }

    [Required(ErrorMessage = "Text is required")]
    [DataType(DataType.MultilineText)]
    public string Text { get; set; }

    [Required(ErrorMessage = "Publish Date is required")]
    [DataType(DataType.DateTime)]
    public DateTime PublishDate { get; set; }
}

My cshtml page includes the following.

Create

@using (Html.BeginForm()) { @Html.ValidationSummary(true)
Post
@Html.LabelFor(model => model.Title)
@Html.EditorFor(model => model.Title) @Html.ValidationMessageFor(model => model.Title)
@Html.LabelFor(model => model.Text)
@Html.EditorFor(model => model.Text) @Html.ValidationMessageFor(model => model.Text)
}

Web Config:




Layout:


@ViewBag.Title


So, the Multiline Text annotation works and creates a text area. But none of the validations work client side. I don't know what i might be missing. Any ideas?? i can post more information if needed. Thanks!

6
задан Community 23 May 2017 в 12:03
поделиться