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 MVC into a web application project.
http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx
But I don't have a WEP APPLICATION PROJECT.
Is there any way for my problem too?
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
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#" %>
Add the following after
add the following inside application_start
At this point, your global.asax should look like
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)
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🕗. Could not add the reference directly because the link can be broken.
Hope this should help you
Converting the whole Web Site to a Web App (WAP) is likely to be painful, so I don't suggest it. You can try the other suggestion from @Grievoushead of making MVC work in a Web Site project (which can work), but I'll suggest an alternate one.
Instead of trying to 'merge' the Web Site and MVC WAP, try keeping them mostly separate, but sharing the same folder. You could do something like this:
A bit unusual, but depending on the exact situation, this may be a good approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With