MVC-在哪里实现表单验证(服务器端)? [英] MVC - where to implement form validation (server-side)?

查看:70
本文介绍了MVC-在哪里实现表单验证(服务器端)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在对传统的MVC应用程序进行编码时,对服务器端表单验证进行编码的最佳实践是什么?代码是属于控制器层还是模型层?为什么呢?

In coding a traditional MVC application, what is the best practice for coding server-side form validations? Does the code belong in the controller, or the model layer? And why?

推荐答案

来自维基百科:

模型视图控制器(MVC)是一种用于软件工程的架构模式.模式的成功使用将业务逻辑与用户界面考虑隔离开来,从而使应用程序更容易修改应用程序的外观或基础业务规则,而又不影响其他规则.在MVC中,模型代表应用程序的信息(数据)和用于操纵数据的业务规则;该视图对应于用户界面的元素,例如文本,复选框项目等;控制器管理与通讯相关的详细信息,以与诸如击键和鼠标移动之类的用户动作模型进行通信.

Model-view-controller (MVC) is an architectural pattern used in software engineering. Successful use of the pattern isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the application or the underlying business rules without affecting the other. In MVC, the model represents the information (the data) of the application and the business rules used to manipulate the data; the view corresponds to elements of the user interface such as text, checkbox items, and so forth; and the controller manages details involving the communication to the model of user actions such as keystrokes and mouse movements.

因此,模型-它包含应用程序和业务规则.

Thus, model - it holds the application and the business rules.

这篇关于MVC-在哪里实现表单验证(服务器端)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆