我是否应该拆分我的意见分成​​了很多小的意见或只是让一个大的景观? [英] Should I split my Views up into a lot of small Views or just make it one big View?

查看:99
本文介绍了我是否应该拆分我的意见分成​​了很多小的意见或只是让一个大的景观?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作的一个MVC 3网络应用项目中,我需要在头版上显示大量的信息。我在网页布局和设计相对较新,所以我已经在如何构建code背后本页方面碰了壁。

I am currently working on an MVC 3 Web app project where I need to display a lot of information on the front page. I am relatively new at web page layout and design so I have hit a wall in terms of how to structure the code behind for this page.

我的第一个想法是到页面(视图)分割成多页(小查看)尽可能使视图模型更小,更易于管理。虽然我不知道这是要去关于它的正确途径。或者我应该尝试以适应页面的所有需求到一个视图中,将显示我需要的所有信息?

My first thoughts were to split the page (View) up into as many pages (small Views) as possible so the View Models are smaller and easier to manage. Although I am not sure if this is the correct way of going about it. Or should I try to fit all the needs of the page into one view that will display all the information I need?

推荐答案

您会得到很多好处,从拆分大视图对象分解为较小的观点,主要是可重用性,可测试性和你不会有这样做的事实(不可避免地)从现在起两个月了。

You will get a number of benefits from splitting a large view object into smaller views, primarily reusability, testability and the fact you won't have to do it (inevitably) two months from now.

采用较小的意见会先给你重用在项目的其他部分这些观点的能力(应该有一个如有必要,但机会相当高,你会)。使用单一的视图给你没有这样的灵活性。

Using smaller views will first give you the ability to reuse those views in other parts of the project (there should be an "if necessary", but the chances are fairly high that you will). Using a single view gives you no such flexibility.

较小的意见也将是简单的概念化(一个简洁,适当命名视图将节省您通过一个百行,以读取时间),保持(您可以隔离错误,和功能更改为每个视图,而不会影响其他)和测试(时间,复杂性和依赖注入)。

Smaller views will also be simpler to conceptualize (a concise, properly-named view will save you the time to read through its one-hundred lines), to maintain (you can isolate bugs, and feature changes to each view without affecting others) and to test (in time, complexity and dependency injection).

您不要使用单一的,堆积如山的观点(当然,可能还有发展的分钟),但你在长(短)期错过了什么,是巨大的收获任何东西。

You do not gain anything by using a single, humongous view (well, perhaps a couple of minutes of development), yet what you miss in the long (and short) period, is substantial.

要使用几个较小的意见MVC3您可以使用主视图内局部视图,

To use several smaller views in MVC3 you can use partial views inside the main view,

<div>
  @Html.Partial("_PartialView", new PartialViewModel)
</div>

这篇关于我是否应该拆分我的意见分成​​了很多小的意见或只是让一个大的景观?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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