Item types in MVC

Topics: Developer Forum
Mar 16, 2009 at 12:50 AM
Hi. I'm evaluating using N2 with MVC. I ran the MVC Sample and the templates sample and I found that with templates I can create a lot of diferent item types (news, polls, static content, etc) and I have an interesting list of available zones that arent present with MVC (in MVC I can create only pages and news). My question is, how can I have that types of items in MVC?
Mar 16, 2009 at 5:12 PM
Hi there,

What I have done is to inlcude the Templates project in my MVC app and make my own MVC abstractpage base class that extends the N2.Templates.Items.AbstractContentPage that I can use to build my own pages in MVC with. Like so:

using N2.Details;
using N2;
using N2.Web.Mvc;
using N2.Templates.Items;

namespace MyNamespasce.Models
public abstract class MVCAbstractPage : AbstractContentPage

This gives you all of the zones, published range and other things in your new Page items -- bear in mind that you need to override TemplateUrl to point to a new MVC view (one that inherits System.Web.MVC.ViewPage) and that for some items you will need to replicate any WebForms logic MVC style (this can be more or less complicated depending on what you are extending).  This is by no means a foolproof or simple solution, there is some work involved, but it is possible to have much of the Templates project available in an MVC app.
Mar 16, 2009 at 7:03 PM
Hi!. Thanks for your replay. I tried your solution and it seems to work, but I got a lot of runtime errors. Do you have a working sample that I can download?
Mar 17, 2009 at 12:44 AM
it would be awesome to have a sample project of your idea working with some extensions already done!!!

It would be awesome for everybody to exchange their work on this so that at some point a full MVC template project would be release.

At the same time, i guess making the transition is a nice way to learn some details of n2CMS.
Mar 17, 2009 at 1:30 AM
ya after some time it seem there a lot to do hehe

where is the n2:box, n2:path, n2:menu code are??? seem that those and surely other are not even found in the aspx or master pages. When I reference the template.dll in the MVC project and do what your saying.