I have a class generated by the Linq2Sql. I try to add the client validation to its properties, so I do the following:
[MetadataType(typeof(ResourceMetadata))]
public partial class Resource
{
// Resource is a class in the LINQ to SQL generated data context.
}
public class ResourceMetadata
{
[Required(ErrorMessage = "error !")]
public string NewsTitle { get; set; } // the NewsTitle property is also in generated Resource class
}
then, in my View,
<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>
<%Html.EnableClientValidation(true); %>
<% using (Html.BeginForm()) { %>
<%: Html.ValidationSummary(true) %>
<div class="editor-label">
<%: Html.LabelFor(model => model.NewsTitle) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.NewsTitle) %>
<%: Html.ValidationMessageFor(model => model.NewsTitle) %>
</div>
<input type="submit" value="Create" />
<% } %>
the Web.config file
appSettings
add key="webpages:Version" value="1.0.0.0" add key="ClientValidationEnabled" value="true" add key="UnobtrusiveJavaScriptEnabled" value="true"appSettings
but still, the validation is not working, nothing shows, the model is passed to the server. Why ?