How to integrate asp.net mvc to Web Site Project

后端 未结 3 1469
甜味超标
甜味超标 2020-12-17 19:45

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

I have followed some tutorials about it but all of them are about integrating

3条回答
  •  粉色の甜心
    2020-12-17 20:20

    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.

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

    1. Install ASP.NET MVC 3

    2. Modify web.config

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

    enter image description here

    3. Modify global.asax

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

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

    enter image description here

    Add the following after

    enter image description here

    add the following inside application_start

    enter image description here

    At this point, your global.asax should look like

    enter image description here

    4. Creating the controller

    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

    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

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

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

    enter image description here

    5. Test the site

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

    The above contents are taken from here

提交回复
热议问题