View和Controller可以调用getter和setter方法吗? [英] Can Views and the Controller call getters and setters methods?

查看:127
本文介绍了View和Controller可以调用getter和setter方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一堆序列图,并想知道如果视图和控制器对象生命线调用getters方法是否可以,尽管它们包含在模型中。



你能告诉我一些例子吗?

I am writing a bunch of sequence diagrams and was wondering if it's okay if the Views and Controller Object lifelines call the getters methods, although they are contained in the Model.

Can you show me some examples?

推荐答案

MVC是一种设计模式。你可以做什么,你应该做什么/不该做什么是两件事。

首先,控制器的一个主要作用是操纵模型 - 因此调用模型方法是正常的来自行动。

从视图中操纵模型的情况较少见。我建议你不要这样做。由于操作调用/返回视图,因此您应该能够处理来自控制器的所有操作。如果需要,可以使用 Html.RenderAction 从视图中调用子操作。
MVC is a design pattern. What you can do and what you should/shouldn't do are two different things.
First of all, one major role of the controller is to manipulate the model - thus it is normal to call model methods from the actions.
It is less common to manipulate model from the view. I suggest you don't do that. Since the views are "called/returned" by the actions, you should be able to handle all manipulation from the controllers. If you need, you can call child actions from the view using Html.RenderAction.


这篇关于View和Controller可以调用getter和setter方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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