如何将消息插入到取决于会话值的视图中。 ASP.NET MVC。最佳实践

发布于 2024-09-03 11:12:57 字数 532 浏览 4 评论 0原文

用户必须填写多步骤调查问卷网络表单,步骤消息取决于用户一开始选择的选项。消息存储在 web.config 文件中。我使用 asp.net mvc 项目、强类型视图,并将业务逻辑与静态类中的控制器分开。我不想让业务逻辑依赖于 web.config。 好吧,我必须根据会话值将消息插入视图中。

至少有 2 个选项可以实现此目的:

  1. 视图模型具有在控制器/业务逻辑中填充并在视图中呈现的属性,例如 <%: Model.HelpMessage1 %>。我必须将 web.config 值从控制器传递到businessLogic,这使得业务逻辑方法签名过于复杂。

  2. 创建从视图中调用的静态帮助器类,如 <%: ViewHelper.HelpMessage1(Model.OptionChosenAtTheVeryBeginning) %>。但在这种情况下,逻辑显示的内容似乎分为两类:业务逻辑和业务逻辑。查看助手。

你会建议什么?

先感谢您!

User have to populate multistep questionnaire web-forms and step messages depend on the option chosen by user at the very beginning. Messages are stored in web.config file. I use asp.net mvc project, strong typed views and keep business logic separated from controller in static class. I don't want to make business logic dependency on web.config.
Well, I have to insert message into view that depends on session value.

There are at least 2 options how to implement this:

  1. View model has property that is populated in controller/businessLogic and rendered in view like <%: Model.HelpMessage1 %>. I have to pass web.config values from controller to businessLogic that makes business logic methods signature too complex.

  2. Create static helper class that is called from view like <%: ViewHelper.HelpMessage1(Model.OptionChosenAtTheVeryBeginning) %>. But in this case logic what to show seems to be separated into two classes: business logic & viewHelper.

What will you suggest?

Thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

箹锭⒈辈孓 2024-09-10 11:12:57

正如阿德里安指出的,你的问题属于业务领域。为什么不获取消息,并将其与其他数据/模型一起放入视图模型中。

As Adrian pointed out, your problem belongs in the business domain. Why not get the message, and put it into a view model along with your other data/models.

甜尕妞 2024-09-10 11:12:57

看来,决定必须显示哪些消息和/或如何从这些消息组装模型是业务逻辑的一部分。如何将消息存储在业务层中并让业务层使用填充的消息生成模型?

It appears that deciding which messages have to be displayed and / or how models are assembled from these messages is part of your business logic. How about storing the messages in your business layer and let your business layer generate the model with populated messages?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文