mercredi 3 juin 2015

MVC in web and client-side validation

Assumptions:

  • In MVC, model is the layer which keeps domain logic, so data validation must be done in the model and not in view/controller code.

  • Specifically in my case, no client-side MVC framework is used to sync model between client and server

In a standalone local application, the view could communicate with the model (directly or using controller as proxy depending on the MVC variant) and request data validation.

However, in the web, if you are not using a client-side MVC framework, the model and controller are in the server and the view is in the client, so the issue becomes a little more complex. I see 3 options:

  • Break MVC pattern and do data validation directly in view
  • Break DRY principle and duplicate part of the model in the view
  • Move a part of the controller to the client. This client code will request data validation to the model in the server via AJAX.

All options use Javascript.

I think the last option (which keeps data validation in server) is the best. Is that correct?




Aucun commentaire:

Enregistrer un commentaire