Is it possible to toggle Validation Data Annotations on/off in MVC 3?

前端 未结 3 537
别跟我提以往
别跟我提以往 2021-01-13 20:36

I have two separate VIEWS accessing the same MODEL. When I put the validator data annotations on the model, it works as advertised and prevents the data from being submitte

3条回答
  •  鱼传尺愫
    2021-01-13 21:06

    I too would suggest using a different view model object. This article has a nice example of how to implement it cleanly http://lostechies.com/jimmybogard/2009/06/30/how-we-do-mvc-view-models/

    Alternatively, you could simply not call ModelState.IsValid on the controller.

提交回复
热议问题