Michael
Michael

Reputation: 421

C# MVC 4, Area Routes, using main views?

I have a basic project with areas in it, I have registered my routes in this area and have used a Lowercase URL extension. Here is the code:

using System.Web.Mvc;

using Web.Modules;

namespace Web.Areas.Services
{
    public class ServicesAreaRegistration : AreaRegistration
    {
        public override string AreaName
        {
            get
            {
                return "Services";
            }
        }

        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRouteLowercase(
                "Services", // Route name
                "services/{controller}/{action}/{id}", // URL with parameters
                new { controller = "Services", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
                new string[] { "Web.Areas.Services" }
            );
        }
    }
}

But now when I go to http://localhost/services/home it shows me my HomeController's Index View, what can I do to fix this? I have already added the namespaces and added the area to the routedata.

Thanks for any assistance

Upvotes: 0

Views: 1813

Answers (1)

m1kael
m1kael

Reputation: 2851

Seems like you either don't have the folder Areas/Services/Views/Home at all or the Index view in that folder. In this case, ASP.NET MVC will fallback to displaying your Index view from the Views/Home (no area) folder. If you need a different view for your area, you need to create it in the area's Views/[Controller Name] folder (or the Shared folder, of course).

Upvotes: 1

Related Questions