Where does input validation belong in an MVC appli

2019-03-12 13:13发布

I have a MVC application that receives an input from a form.
This is a login form so the only validation that is necessary is to check whether the input is non-empty.
Right now before I pass it to the model I validate it in the controller.
Is this a best practice or not? Does it belong to the model?

7条回答
时光不老,我们不散
2楼-- · 2019-03-12 13:54

Assuming your application is structured like:

  • Model-View-Controller
  • Service
  • Persistence
  • Model

The user input would come to your controller, and you would use services in the service layer to validate it.

查看更多
登录 后发表回答