View和Controller可以调用getter和setter方法吗?

编程入门 行业动态 更新时间:2024-10-28 09:13:23
本文介绍了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方法吗?

本文发布于:2023-05-27 09:56:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/285724.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:词库加载错误:Could not find file 'D:\淘小白 高铁采集器win10\Configuration\Dict_Sto

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!