Why don't DataAnnotations work in open fields? Example:
namespace Models
{
public class Product
{
[Display(Name = "Name")]
public string Title;
}
}
public ActionResult Test()
{
return View(new Models.Product() { Title = "why no love?" });
}
@Html.LabelFor(m => m.Title)
@Html.DisplayFor(m => m.Title)
If Title is a field, the Display attribute seems invalid. If the Title is changed to a property, it works as expected, "Name" is displayed.
It would seem that in this example it’s easy to just change the property, but I'm trying to use types from F # where they are compiled into a class with fields, and not with properties.
This has been tested in ASP.NET 4 and MVC RC 3.
yanta source
share