Question

I'm new to C# and the MVC architecture.. But I'm trying to learn and want to get off on the right foot. The application I'm building will require a front-end and administration area. Both will have every different interfaces and be used by different people so I thought the best way to separate it would be to create an individual project for each, with seperate controllers and views, all sharing the same model.

However, I just cannot seem to register a project as a seperate area. nopCommerce do it for their admin control panel and I've tried going through the code and cannot find the differences.

In my new "admin" project I have an area registration file with the following code:

using System.Web.Mvc;

namespace cmsApp.Areas.Admin
{
public class AdminAreaRegistration : AreaRegistration
{
    public override string AreaName
    {
        get
        {
            return "Admin";
        }
    }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "Admin_default",
            "cmsAdmin/{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", area = "Admin", id = UrlParameter.Optional },
            new[] { "cmsApp.cmsAdmin.Controllers" }
        );
    }
}
}

I'd appreciate any further information on this issue..

I've included the source code I'm working on, if anyone cares to take a look at the full code: https://dl.dropbox.com/u/3901723/cmsApp.rar

Cheers.

Was it helpful?

Solution

If you are bound and determined to have separate projects, then you can use Portable Areas, which are part of the MVC Contrib project.

http://mvccontrib.codeplex.com/

However, you do not need to have separate projects just to have different UI's. By default, Areas have their own Views and Shared Views areas, and use separate master pages. So you can use normal areas and still maintain two separate looks and feels, and different code, and anything else.

The only reason to use separate projects are:

  1. You have different people working on each and want to keep them physically separate for ease of development.
  2. You want make a portable area be a "plug-in" sort of thing, which it sounds to me like that isn't the case.
  3. You want to deploy the areas separately from the main app.

OTHER TIPS

Your namespaces looks wrong.

context.MapRoute(
    "Admin_default",
    "cmsAdmin/{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", area = "Admin", id = UrlParameter.Optional },
    new[] { "cmsApp.Areas.Admin.Controllers" }
);

Maybe you are missing RegisterAllAreas() in your global.asax ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top