MVC Razor Project

Vote:
 

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?

#63762
Nov 28, 2012 19:28
Vote:
 

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

#63767
Nov 29, 2012 3:43
Vote:
 

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.

#63777
Edited, Nov 29, 2012 11:55
Vote:
 

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.

#63806
Nov 29, 2012 22:01
Vote:
 

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

#63807
Nov 29, 2012 22:03
Vote:
 

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.

#63808
Nov 29, 2012 22:10
Vote:
 

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.

#63813
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.