0

I have an active website using umbraco v6 and need to implement a form with a lot of behavior. I can't seem to find a detailed tutorial on how to get started adding mvc elements to an existing site. Every tutorial either starts by making a new MVC project or just tells you to create controllers and doesn't go into much more detail i.e. where to to place controllers and models since there are no folders for them by default. I have tried adding model and controller files and intellisence does not seem to work now. Do I just makes a separate mvc project and deploy it as a binar? Any help would be greatly appreciated.

Thanks,

Brandon

  • You should create your project following a similar format to plain MVC projects. The simplest way to get controllers to work is to use custom controllers whereby you create a controller per document type. So if you had a document type of "ContactUs" you'd have a controller named ContactUsController which would intercept any requests to content which is of type ContactUs. More reading here https://our.umbraco.org/documentation/Reference/Templating/Mvc/custom-controllers – timothyclifford Aug 04 '15 at 17:42

1 Answers1

0

Some months ago we have migrated our Umbraco6-WebForms macros (user control) to Umbraco6-MVC macro (partial view/SurfaceController). I don't know if you have the same scenario, but I can share what we did and I hope this can help you.

Our solution is divided in multiple class library projects that contain both user controls or MVC controllers and one web project that orchestrates and composes the others (with DI , environment configuration, etc).

Thanks to the full compatibility between WebForms and MVC, we were able to do a "slow migration process" from WebForms to MVC, having a long period in which our application was using both type of Macros (WebForms and MVC) in the same time.

These are the steps followed to migrate a project and to create MVC macros.

Update WebForm project to MVC

We followed the instructions described in this article. I.e.

  1. Install MVC 4 (required by Umbraco 6.x) in each project
    • Open Package Manager Console
    • run the following command (we use that particular MVC version because it is the same used by Umbraco 6.2.4): Install-Package Microsoft.AspNet.MVC -Version 4.0.20710.0
  2. Install Microsoft ASP.NET Web Optimization Framework to allow the compilation of Razor scripts, using this command: Install-Package Microsoft.AspNet.Web.Optimization -Version 1.1.3 (see this post)
  3. Unload the project to modify the .csproj file
  4. Insert/add the following tag (under ProjectGuid) to enable MVC scaffolding

    <ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    
  5. reload the project

  6. add these reference to the project if missing: Umbraco, Microsoft.CSharp (it enable the use of dynamic type like ViewBag), ClientDependency.Core.Mvc

Create specific MVC Areas

This step allows us to separate the old webForms parts from the new MVC ones in the same project. Furthermore the VisualStudio scaffolder creates a lot of stuff for you (folders, web.config and much more). To do that, at the project level, Add new Area (you should have this option in the contextual menu after the steps above)

Now you should be able to have new MVC code togheter with webforms.

Create your MVC Umbraco Template

Umbraco allows you to define your default rendering engine. In mixed project you should have MVC in the configuration file. See this post for more info. Now you can create your new template in Umbraco back-office.

It should be a beginning.

Community
  • 1
  • 1
wilver
  • 2,106
  • 1
  • 19
  • 26