asp.net mvc related nullable entities
I'm having some problems with Model.IsValid. I am trying to create a model similar to this...
class Article {
int Id {get; set;}
string Title {get; set;}
Category Category {get; set;}
}
class Category {
int Id {get; set;}
string Name {get; set;}
IList<Articles> Articles {get; set;}
}
I would like that the Article Category can be null. How开发者_运维问答ever Model.IsValid is always false when the Category is null.
Any help appreciated.
Hmmm ... are you sure the Model.IsValid is false because of category being null? I am asking this since I don't see any 'required' data annotations in the Category property in your domain object. OR if it is indeed failing when binding on the Category then you might need to create a custom model binder which is where I think - more likely a guess - your error is happening.
精彩评论