0

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 ?

[SOLVED]

The namespaces of the generated class and my class were different. I had to change them to be the same.

1 Answer 1

1

Because you haven't enabled in View page.

Use this

Html.ValidationSummary(true) // you have set it false
Sign up to request clarification or add additional context in comments.

4 Comments

yes, not working even if I set Html.ValidationSummary(false). I've followed by this answer stackoverflow.com/a/2499352/106616
Are the Linq2Sql generated classes and MetaData classes in the same assembly?
I fixed it - my own class was in different namespace. When they were the same - it worked. I didn't know that it is important cuz I'm new in the partial classes. Thanks guys !
The moment @epignosisx asked this question and i had the feeling he is hit the nail on the head. Thanks to him and good luck to you :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.