简体   繁体   English

MVC应用程序中有什么? (Visual Studio 2008/2010)

[英]What is in an MVC application? (Visual Studio 2008/2010)

When you create a new MVC application, how is it different than a Web Application? 创建新的MVC应用程序时,它与Web应用程序有何不同?

I can put a route handler in global.asax even in a Web Application. 我甚至可以在Web应用程序中将路由处理程序放在global.asax中。 But an MVC application has more than that, it even has the context menu to create controllers and views. 但是,MVC应用程序不仅仅具有此功能,甚至还具有用于创建控制器和视图的上下文菜单。

I am wondering if it is possible to turn an existing Web Application into an MVC application...? 我想知道是否有可能将现有的Web应用程序转换为MVC应用程序...?

Basically MVC application IS ASP.NET application. MVC应用程序基本上 ASP.NET应用程序。 The difference is that it has reference to 不同之处在于它参考了

  • System.Web.Routing System.Web.Routing

  • System.Web.Abstractions System.Web.Abstractions

  • System.Web.Mvc System.Web.Mvc

dll-s. DLL-S。 Also it has some additional configuration in the web.config and a routes registration in Global.asax. 它还在web.config中具有一些其他配置,在Global.asax中具有路由注册。 The MVC application also comes with default folders for controllers, views and data. MVC应用程序还带有用于控制器,视图和数据的默认文件夹。 It is not mandatory to use the same folders though. 虽然不是必须使用相同的文件夹。 You can easily turn existing ASP.NET application into MVC app. 您可以轻松地将现有的ASP.NET应用程序转换为MVC应用程序。 For more detailed info you can check this article http://www.packtpub.com/article/mixing-asp.net-webforms-and-asp.net-mvc 有关更多详细信息,您可以查看本文http://www.packtpub.com/article/mixing-asp.net-webforms-and-asp.net-mvc

I assume you are talking in specific about ASP.NET MVC. 我假设您是在专门谈论ASP.NET MVC。 So my answer is mostly geared towards it. 所以我的答案主要是针对它的。

ASP.NET MVC is an implementation of the tried and tested MVC design pattern. ASP.NET MVC是久经考验的MVC设计模式的实现。 MVC has been used in the computer software construction for about more than 2 decades but has come into prominence in the last few years. MVC在计算机软件构造中已使用了大约20多年,但在最近几年中已成为举世瞩目。 Especially this approach to software construction was popularised by Ruby on Rails. 特别是这种软件构建方法已由Ruby on Rails普及。 ASP.NET MVC goes along the same lines but adds its own quirks and advantages. ASP.NET MVC遵循相同的原则,但增加了自己的怪癖和优势。

When applying MVC design pattern emphasis is given to clear separation of concerns. 在应用MVC设计模式时,重点是要清除关注点。 Your View concerns are implemented in the views - via HTML, CSS, javascript, View Helpers and ViewModels. 您的视图关注点通过HTML,CSS,JavaScript,View Helpers和ViewModels在视图中实现。 Your data concerns - data that will be used and rendered by the views is implemented in your Model layer. 您的数据问题-视图将使用和呈现的数据在模型层中实现。 Your Controllers facilitate the interaction between your view layer and your model layer, concerns such as retrieving data, updating data, manipulating data etc. 您的控制器可方便您的视图层与模型层之间的交互,例如检索数据,更新数据,操纵数据等问题。

This design pattern might not be suitable for all types of software construction. 此设计模式可能不适用于所有类型的软件构造。 However, for almost all types of software that requires interacting with the user, MVC greatly simplifies the construction and maintenance of software. 但是,对于需要与用户交互的几乎所有类型的软件,MVC都极大地简化了软件的构建和维护

Using the above pattern ASP.NET MVC greatly simplifies web application development. 使用以上模式,ASP.NET MVC大大简化了Web应用程序的开发。 This is made even better with the usage of conventions such as appending 'Controller' in the name of the controllers, Usage of folders for different concerns, URL routing conventions etc. 通过使用约定,例如在控制器的名称中附加“ Controller”,针对不同问题的文件夹的使用,URL路由约定等,可以使这种情况变得更好。

One benefit of ASP.NET MVC is that it makes working with pure HTML, CSS and javascript easier. ASP.NET MVC的一个好处是,它使使用纯HTML,CSS和javascript更加容易。 It also does away with Viewstate and any performance limitations associated with it. 它还消除了Viewstate及其相关的性能限制。

take a look at this good post: 看看这个好帖子:

How does the MVC pattern differ, if at all, from the DAL / BLL design pattern? 如果有的话,MVC模式与DAL / BLL设计模式有何不同?

MVC is a design pattern which is different especially in UI handling. MVC是一种设计模式,尤其是在UI处理方面有所不同。 So if you have an application which has 3 layers UI, BLL and DAL you can still use BLL and DAL. 因此,如果您的应用程序具有3层UI,BLL和DAL,您仍然可以使用BLL和DAL。 But the UI is very different. 但是用户界面却大不相同。 MVC design pattern has a model, a view and an controller. MVC设计模式具有一个模型,一个视图和一个控制器。 So the model is just the object from lets say a person class. 因此,模型只是假设一个人的类的对象。 The view is the UI the user gets displayed. 该视图是用户显示的UI。 The big advance is that several views can use the same controller. 最大的进步是,多个视图可以使用同一控制器。 And the controller checks the correctness of the fields and does your code behind stuff. 控制器检查字段的正确性,并在后面进行代码编写。

So you can reuse your BLL and DAL and have to change your UI of your existing website. 因此,您可以重复使用BLL和DAL,并且必须更改现有网站的UI。

That's the way I got the MVC design pattern. 这就是我获得MVC设计模式的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM