I'd like to add MVC support to an existing Website project (not a Web application project) and have a few questions.
.csproj
file's <ProjectTypeGuids>
node. There is no csproj
file in a website project. Models
and Controllers
folder in the App_Code
. Is this true? I prefer having these folders under root.Views
should I be creating a aspx
and aspx.cs
files? Is cshtml
razor files supported in this kind of a setup?Any other responses are appreciated. Thanks
ASP.NET gives you a powerful, patterns-based way to build dynamic websites using the MVC pattern that enables a clean separation of concerns.
In order to add a Web API Controller you will need to Right Click the Controllers folder in the Solution Explorer and click on Add and then Controller. Now from the Add Scaffold window, choose the Web API 2 Controller – Empty option as shown below. Then give it a suitable name and click OK.
MVC is a pattern known as Model-View-Controller. It is made up of three pieces; Model, View, and Controller that interact with each other to provide capabilities to the application that implements it. MVC is related to ASP.NET in much the same way as it is to an application.
MVC - allows developers to create websites or specific pages using the Model-View-Controller architectural pattern (based on the ASP.NET MVC framework). Working with this model requires knowledge of programming and ASP.NET MVC.
With asp.net MVC2 and above, the MVC team separated the core functionality into three different assemblies, each of which extends from the common System.Web assembly:
With this seperation, they went ahead and made the assemblies to "work in Medium-trust server enviroments and be bin-deployable".
One of the good things about this featuere is, you don't have to have a specific project type to run MVC. You only need the assemblies, some directories and a tweaked web.config.
To do this, you need only to place the assemblies in your local bin folder of your project and make the necessary references for those assemblies. Once this is done, you have access to asp.net MVC.
Here are some detailed instructions from the Wrox Professional ASP.NET MVC 1.0 book which should help you get started:
Including MVC in Existing Web Forms Applications
Adding ASP.NET MVC functionality to an existing Web Forms application is comprised of three different steps:
1. Add a reference to the three core libraries that ASP.NET MVC needs: System.Web.Mvc, System.Web.Routing, and System.Web.Abstractions.
2. Add two directories to your application: Controllers and Views.
3. Update the Web.config to load the three assemblies at run time as well as registering the UrlRoutingModule HttpModule.
For reference, here are a couple of blogs/sites which have some more detailed scenarios which might help you out:
Mixing ASP.NET Webforms and ASP.NET MVC
ASP.NET WebForms and ASP.NET MVC in Harmony
Good luck, and hope this helps you out some.
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