Disable Model Validation in Asp.Net MVC

前端 未结 7 974
没有蜡笔的小新
没有蜡笔的小新 2020-12-09 20:41

How do I disable Model validation for a single Action in a Controller ? Or can I do it per model by registering the model type at startup somewhere ?

I want the Mode

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 21:29

    I would recommend you perform validation in both places rather than trying to turn off validation in the UI. I understand your point that the service cannot assume that it's being passed valid data - that is a valid concern and is the reason your service should have validation. But you should also have validation in your UI. This is also nice because you can have client-side validation to prevent user errors and give you users a better experience.

提交回复
热议问题