- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我正在阅读的一本关于使用 MVC 进行应用程序设计的书的摘录:
Ideally, the view is so simple and logic-free as to need virtually no testing. Users (and developers before users) can reasonably test the view by simply looking at the pixels on the screen. Anything else beyond pure graphical rendering should ideally be taken out of the view and placed in the controller and model. This includes, for example, the logic that determines whether a certain button should be enabled or grayed out at some point.
大胆的声明对您意味着什么?这会是什么样子?
谢谢,杆。
最佳答案
决定何时启用或禁用按钮的逻辑应该驻留在 Controller 中,并简单地调用一个方法,例如 view.EnableContinueButton() 来启用/禁用页面上的按钮。
启用/禁用页面上按钮的实际代码应该在 View 中实现,例如 EnableContinueButton() 方法,然后调用类似 btnContinue.Enable() .
简单地说, View 应该关注 UI 细节(显示/隐藏/启用/禁用 UI 元素)并将所有业务逻辑处理留给 Controller 。通过这种方式, Controller 无需关心 UI 元素, View 独立于实际业务逻辑工作。
例如在 Controller 中,
public void ProcessOrder()
{
if (!controller.ValidateOrder(model.OrderNo))
view.EnableContinueButton(false);
else
// Process the order
...
}
在 View 中
public void EnableContinueButton(bool enabled)
{
btnContinueButton.Enabled = enabled;
}
坦率地说,我在 MVC 方面没有太多经验(前一段时间在一个项目中实现过),但我希望 Controller 和 View 之间的逻辑分离足够清晰。
关于asp.net-mvc - mvc中禁用或不禁用按钮的逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2650436/
我是一名优秀的程序员,十分优秀!