MVC Razor Project


EPiServer noob here. I've done plenty with ASP.NET and MVC so I'm not entirely new to enterprise web apps. I have 7 installed locally and it's mostly working ok with my Visual Studio project. Creating page types and all has been no problem.  I'm trying to see if I can run a pure MVC 4 Razor site. What I can't seem to figure out is how to set up a template the CMS recognizes and I can set a Page Type's template to. How do you add an item to the MVC template drop down in CMS?

Nov 28, 2012 19:28

the templates are pulled from the controllers.  so you should have controller : basecontroller<pagetypemodel>.  this will register in the dropdown for templates.

Nov 29, 2012 3:43

The general idea is that you create content type (this is your model), razor view for this type (view) and controller<yourcontenttype> (which is considered as template). Probably you will also have to add some configuration to make razor work with your model.

I blogged about creating simple add-on with shared block that supports MVC and Web Forms rendering. The code was written for EPiServer 7 Preview, but the ideas stay the same. You can also find example of razor engine configuration in "MVC block rendering" subsection. You probably don't need that tricks with helping MVC to find the view in add-on folder, when your views are deployed in standard locations for MVC views.

There is couple of helpful articles in SDK:

Pages, Page Types and Page Templates

Blocks, Block Types and Block Templates

Creating Page Templates and Block Controls

Editing hints in MVC

Don't forget about proper client resources handling in your templates.

Edited, Nov 29, 2012 11:55

Thanks for the responses. I was able to get a template to show up in CMS. Now I'm getting a YSOD with this message:

The model item passed into the dictionary is of type 'Castle.Proxies.MyPageProxy'

but this dictionary requires a model item of type 'MyProject.Models.Pages.MyPageViewModel'.


Seems odd to me that the CMS is yellow screening but my project compiles with no issues.

Nov 29, 2012 22:01

When you return your model to the view, what type are you returning, by the looks of it, your returning the MyPageProxy and your view is looking for MyPageViewModel.  More code would also be helpful

Nov 29, 2012 22:03

Ahhh!!! Good catch Joshua. I changed the model to MyPage (a type) and now it appears to be working. Seems with the step of setting up a page type on top of the model kinda threw me off.  I think I was trying to not let the EPiServer extensions do their job.

Nov 29, 2012 22:10

Remember that in MVC, theres no magic when creating somthing from a Visual studio template, so feel free to just create a standard razor for your view and a standard c# class for youre controllers.

Nov 30, 2012 8:53
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.