Mvc2 validation summary and required metadata

Posted by Arnis L. on Stack Overflow See other posts from Stack Overflow or by Arnis L.
Published on 2010-02-07T09:41:18Z Indexed on 2010/03/09 8:06 UTC
Read the original article Hit count: 580

source code...

Thing is, if i specify required metadata using fluent modelmetadata provider like this=>

public class Foo
    {
        public string Bar { get; set; }
    }

    public class FooModelMetadataConfiguration : ModelMetadataConfiguration<Foo>
    {
        public FooModelMetadataConfiguration()
        {
            Configure(x => x.Bar)
                .Required("lapsa") ;
        }
    }

And write this into my view =>

<% Html.BeginForm(); %>
<%= Html.ValidationSummary() %>
<%= Html.TextBoxFor(x=>x.Bar) %>
<% Html.EndForm(); %>

And add this to home controller =>

 [HttpPost]
 public ActionResult Index(Foo foo)
 {
       ViewData["Message"] = "Welcome to ASP.NET MVC!";

       return View(foo);
 }

It will output this html =>

<div class="validation-summary-errors">
  <ul>
    <li>lapsa</li>
    <li>The Bar field is required.</li>
  </ul>
</div>

I can't understand why 2nd error is rendered and how to omit it.

Author of System.Web.Mvc.Extensibility framework replied with =>

I think this is a known issue of asp.net mvc, i could not remember the exact location where I have read it, I suggest you post the issue in asp.net mvc issue tracker over codeplex.

But before i post anything on issue tracker - i would like to understand first what exactly is wrong.

Any help with that?

© Stack Overflow or respective owner

Related posts about asp.net-mvc-2-validation

Related posts about asp.net-mvc-2