如何asp.net MVC集成到网站项目 [英] How to integrate asp.net mvc to Web Site Project

查看:275
本文介绍了如何asp.net MVC集成到网站项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我在标题中提到的,我有一个巨大的网站项目,我想补充MVCinto它。

As I mentioned in title, I have a huge WEB SİTE PROJECT, and I want to add MVCinto it.

我按照一些关于它的教程,但个个都是关于集成到MVC的Web应用程序项目。

I have followed some tutorials about it but all of them are about integrating MVC into a web application project.

<一个href=\"http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx\" rel=\"nofollow\">http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx

但我没有一个WEP应用程序项目。

But I don't have a WEP APPLICATION PROJECT.

有什么办法我的问题呢?

Is there any way for my problem too?

推荐答案

有关于如何获取MVC与ASP.NET Web应用程序的工作很多博客文章。但是仍有场景中,我们使用的是普通的ASP.NET网站项目,而不是Web应用程序项目。

There are numerous blog posts on how to get MVC to work with ASP.NET Web Applications. However there are still scenarios where we are using normal ASP.NET website projects rather than Web Application projects.

下面是启用MVC 3与一个asp.net网站项目的步骤

Below are the steps to enable MVC 3 with an asp.net website project

1。安装ASP.NET MVC 3

2。修改web.config中

在Visual Studio中打开web.config文件,并添加部分内以下行

Open up web.config in Visual Studio and add the following lines inside the section

3。修改Global.asax中

接下来,您将需要在code增加对MVC触发器中的Global.asax(创建一个如果不存在的话)

Next you will need to add in the code for MVC triggers inside global.asax (create one if it does not exist)

&后下添加以下行;%@应用程序语言=C#%>

Add the following lines after <%@ Application Language="C#" %>

添加以下后

添加以下里面的Application_Start

add the following inside application_start

在这一点上,你的Global.asax应该看起来像

At this point, your global.asax should look like

4。创建控制器

由于这是一个网站项目,编译在运行时,所以你必须创建APP_ code文件夹内的控制器,而不是在主网站

Because this is a website project, compilation is at runtime, so you will have to create your controllers inside the App_Code folder rather than the normal Controller folder in the main site

请注意,您的控制器类需要与控制器关键字来结束。在这个例子中,与控制器=家,为控制器的类名必须HomeController的

Note that your controller class needs to end with the Controller keyword. In the example, with a controller = "Home", the classname for the controller needs to be HomeController

要添加您的第一个控制器,右击APP_ code文件夹,并创建一个新的类文件名为HomeController.cs

To add your first controller, right click on the App_Code folder and create a new class with the file name as HomeController.cs

以下code粘贴到HomeController.cs(取代一切)

Paste the following code into the HomeController.cs (replace everything)

5。测试网站

现在,您已经生成路由,并创建了控制器,浏览到localhost /家。你应该看到Hello World

Now that you have generated the routing and created the controller, browse to localhost/home. You should see "Hello World"

以上内容从 <一所href=\"http://jefferytay.word$p$pss.com/2012/04/10/getting-asp-net-mvc-3-to-work-with-asp-net-website-project/\">here.无法添加引用,因为直接链接可以打破的。

The above contents are taken from here. Could not add the reference directly because the link can be broken.

希望这会帮助你。

这篇关于如何asp.net MVC集成到网站项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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