谁负责对字符串进行编码?

发布于 2024-08-03 02:19:15 字数 159 浏览 3 评论 0原文

谁负责对字符串、模型或视图进行编码?

我有一个来自数据库的字符串,它来自用户 - 我想在数据库中保留尽可能多的信息,所以我逐字保存输入。

当我要显示字符串时,我应该在填充视图模型时对其进行编码,还是应该由视图决定是否要显示编码的字符串?

谢谢,
K

Who's responsibility is it to encode a string, the model or the view?

I've a string from a database, it's come from the user - I want to keep as a much information as possible in the database, so I'm saving the input verbatim.

When I come to display the string, should I be encoding it when I populate the view model, or should the view decide if it wants to display it encoded or not?

Thanks,
K

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

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

发布评论

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

评论(2

攒眉千度 2024-08-10 02:19:16

我认为这主要与您希望视图的干净程度有关。如果您在视图端进行编码,则可以使控制器免于数据操作操作,同时使视图与丑陋的脚本标签混淆,但是如果您在控制器端进行编码,您将拥有一个更干净的(对设计人员更友好) 查看控制器中可能令人困惑的代码。

真正的问题是您愿意混淆后端代码还是视图标记?

一般来说,我相信最佳实践是在您看来,以便您的控制器能够在不改变其操作方式的情况下转变为不同的输出流。

I think this mostly pertains to how clean you'd like your View. If you encode on the view end you keep your controller free of data manipulation operations while muddling the view up with ugly script tags, however if you do it on the controller end you'll have a cleaner (more designer friendly) view and possibly confusing code in the controller.

The real question is would you rather muddle your back-end code or the view markup?

Generally speaking though I believe the best practice would be in your view so that your controller has the ability to morph to different output streams without changing how it operates.

绝情姑娘 2024-08-10 02:19:15

视图

两者之间的区别在于模型保存数据,而视图负责基于输出介质显示数据。因为如果您想通过某种非 HTML 媒体传输此数据,您可能不希望对其进行 HTML 编码。

The View

The difference between the two is that The Model holds that data and The View is responsible for showing the data based on the output medium. Because if you wanted to transmit this data over some none HTML medium you probably don't want it HTML encoded.

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