开发者

MVC Validation with ViewModel

I have EF4 entities, decorated with DataAnnotations, I have 开发者_JAVA百科my clientside validation enabled in web.config, and everything. It works, except on some views my @model is a MyViewModel where T is one of the EF4 entities:

public class MyViewModel<T>
{
 public T Entity {get;set;}
 public string SomeOtherPropertyWhichDoesntNeedValidation {get;set;}
}

Now for some reason validations on T doesn't work when using in a ViewModel. Just to clarify, the textboxes are generated by @Html.TextBoxFor(o=>o.Entity.Title); etc.

please help

EDIT: This is how my entity looks like

[MetadataType(typeof(TextMeta))]
public partial class Text
{
        class TextMeta
        {
            [Required(ErrorMessage="This is required!!!")]
            public string Title { get; set; }
        }
}


Can you try this?

[MetadataType(typeof(TextMeta))] 
public partial class Text {}

public class TextMeta 
{
    [Required(ErrorMessage="This is required!!!")]
    public string Title { get; set; } 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜