如何在ASP.NET MVC应用到不同的组件单独的模型,视图和控制器 [英] How to separate model, view and controller in an ASP.NET MVC app into different assemblies

查看:159
本文介绍了如何在ASP.NET MVC应用到不同的组件单独的模型,视图和控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我试图进入ASP.NET MVC框架。结果
对于我的大多数测试应用我用一个单一的组装/项目。这对于一些规模较小的应用程序正常工作。然后,我不知道我怎么会放在我的模型,控制器和视图类为独立的组件?在真正的大网络应用,是不太现实的把一切都成一个单一的组装/项目。

At the moment I am trying to get into the ASP.NET MVC framework.
For most of my test applications I used a single assembly/project. This worked fine for some smaller applications. Then I wondered how I could place my model, controller and view classes into separate assemblies? In really big web-applications it is not very realistic to put everything into a single assembly/project.

所以我的问题是:是否有可能告诉ASP.NET MVC框架在另一个组装的意见和/或控制器搜索不失内置路由引擎的灵活性

So my question is: Is it possible to tell the ASP.NET MVC framework to search in another assembly for views and/or controllers without losing the built-in flexibility of the routing engine?

推荐答案

(未知)是正确的。创建两个项目,一个类库和一个MVC Web项目。该MVC项目应该引用包含文件背后的控制器和code(全球ASAX等)类库。下面是一个例子的布局。

(unknown) is correct. Create two projects, a class library and an MVC web project. The MVC project should reference the class library that contains the controllers and code behind files (global asax etc). Here is an example layout.

该类库应只包含的.cs文件,也没有意见(的.aspx / .ascx文件)。

The class library should only contain .cs files and no views (.aspx/.ascx files).


MyProject.BaseSite (class library)
    + Controllers
        - HomeController.cs
        - ... any other controllers
    - default.aspx.cs
    - global.asax.cs

MVC Web项目中应该包含CONFIGS,意见等,并引用到你的类库

MVC web project should contain configs, views etc and a reference to your class library


MyProject.ExampleSite
    + Content
        + scripts
        + css
        + images
    + Views
        + Home
            - index.aspx
            - .. other aspx files
        + Shared
            - Site.master
    - web.config

记住不同的命名空间。然后,您可以创建引用相同code多示例网站。这可以让你有效的皮肤你的网站完全不同。

Remember the different namespaces. You can then create multiple Example websites that reference the same code. This allows you to effectively skin your website completely differently.

这篇关于如何在ASP.NET MVC应用到不同的组件单独的模型,视图和控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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