我们应该如何将数据传递到大型ASP.NET MVC网站中的视图 [英] How should we pass a data to a view in a big ASP.NET MVC web site

查看:93
本文介绍了我们应该如何将数据传递到大型ASP.NET MVC网站中的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

推荐答案

您应该始终使用的MVC方法(尤其是对于简单的网站)可以节省时间,并使应用程序更易于理解.

The MVC approach you should use always, especially for simple sites, it's save your time and make application more understandable.

如果编写的内容超过两页,则需要使用MVVM模式(MVC的增长),在这种情况下,您将无法在ViewModels中使用部分模型".

If you write something larger than two pages, you need to use MVVM pattern (growth of MVC), in that case you will escape from using "partial models" with ViewModels.

模型必须仅包含业务逻辑.

Model must contain only busines logic.

如果始终使用ViewModel(而不是Model)从视图返回数据并将其传递到视图,会更好,因为它提供了一些安全性.

Be better if you will always use ViewModel (not a Model) for returning data from a view and pass it to view, because it provides some safety.

为方便将数据从模型复制到ViewModel的过程,请使用AutoMaper和EmitMapper之类的东西.

For facilitate the procedure of copy data from Models to ViewModels use the things like AutoMaper and EmitMapper.

ViewBag和ViewData仅应用于其他数据(例如DropDown的项目集合)或某些视图文本(例如页面标题).

ViewBag and ViewData you should use only for additional data's like item colections for DropDown, or some view-text like page title.

MVVM模式的另一个优势是更好的可测试性.如果您编写并支持非常庞大的网站,则可以为某些负责的代码部分编写测试.

One more advantage of MVVM pattern is better testability. If you write and support really hugh site you may write tests for some responsible parts of code.

有关更多详细信息,请查看google-MVVM,ASP-MVC.

For more details you can look at google - MVVM, ASP-MVC.

如果我对您的疑问或错过没有感到不满意,请将其写在评论中(添加评论"参考).

If i something not understad in you question or miss, write it in the comment ("add comment" ref).

这篇关于我们应该如何将数据传递到大型ASP.NET MVC网站中的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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