ASP.Net MVC 2 Controller's TryValidate doesn't validate the List<> items within the model

前端 未结 2 914
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-11 08:48

How do you get a model\'s validation to also validate child objects in a generic list property.

I have a model that I\'m trying to validate, this is not what\'s bein

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-11 09:38

    I had a similar issue that I fixed by avoiding the call to TryValidate altogether. The reason I called TryValidate was because I needed to do make some changes on my model and then do the validation. I ended up creating an interface for the model and replaced the default model binder with one that recognizes the interface and calls my method. This all happens before the framework calls validate the first time (which is recursive).

提交回复
热议问题