Revalidating a modified ViewModel within a controller method?

后端 未结 2 1396
耶瑟儿~
耶瑟儿~ 2020-12-08 06:17

EDIT - We\'re using MVC4 Dev Preview....

I\'m implementing an edit page for a FishingTrip class. FishingTrip contains a c

2条回答
  •  猫巷女王i
    2020-12-08 06:37

    Once you have removed the offending item(s), clear the ModelState and validate again, like so:

    ModelState.Clear();
    TryValidateModel(crew);  // assumes the model being passed is named "crew"
    

    Note: Be carefull when use TryValidateModel method because this method does not validate nested object of model (As mentioned by @Merenzo).

提交回复
热议问题