1

This post is directly related to: MVC5 Area not working

That post fixed the index.cshtml issue, however it did not resolve each view for that controller. For example:

http://localhost:45970/Setup/Start gives the error that the resource cannot be found (basically a 404).

However http://localhost:45970/Setup/Setup/Start brings up the correct page.

So what needs to be reconfigured so that ALL views for that controller in the Setup Area will open properly?

Edit 1

Code from SetupAreaRegistration.cs

using System.Web.Mvc;

namespace BlocqueStore_Web.Areas.Setup
{
    public class SetupAreaRegistration : AreaRegistration
    {
        public override string AreaName
        {
            get
            {
                return "Setup";
            }
        }

        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                name: "Setup_default",
                url: "Setup/{controller}/{action}/{id}",
                defaults: new { action = "Index", controller = "Setup", id = UrlParameter.Optional },
                namespaces: new[] { "BlocqueStore_Web.Areas.Setup.Controllers" }
            );
        }
    }
}
Community
  • 1
  • 1
John Schultz
  • 672
  • 1
  • 10
  • 29
  • Is the area named `Setup` or `Admin`? – ekad Aug 17 '16 at 06:41
  • either actually, I have two areas, Admin and Setup. I need both to actually behave properly. Meaning when I goto /Admin/Employees the site pulls up /Areas/Admin/Views/Employees. Likewise with setup /Setup/AddSiteLogin needs to pull up /Areas/Setup/Views/AddSiteLogin page. The same goes for any view located in those two Areas respectively. – John Schultz Aug 17 '16 at 06:47
  • Can you add the code of SetupAreaRegistration.cs ? – ekad Aug 17 '16 at 06:51
  • If you have an Area named Setup, then `http://localhost:45970/Setup/Start` will point to the controller named `Start` under `Setup`. I'd guess you don't have StartController under Setup Area. – ekad Aug 17 '16 at 07:03
  • {Lightbulb} {FacePalm} - I just realized that. No I do not have a Start controller, just have the setup controller. Is there any way to make all the views in the setup controller of that area show up as http://{host}/Setup/{view}, Same with the Admin Area? Its controller is Admin – John Schultz Aug 17 '16 at 07:09
  • If you want `http://{host}/Setup/‌​{view}`, you don't even need a Setup Area. You only need SetupController without Area. Same thing with Admin. – ekad Aug 17 '16 at 07:13
  • OK,... what I was trying to avoid, Thank you :) – John Schultz Aug 17 '16 at 07:16

1 Answers1

1

Since you have an Area named Setup with the above route configuration, opening http://localhost:45970/Setup/Start will execute StartController under Setup Area. You got 404 error because you don't have StartController under Setup Area, but you can open http://localhost:45970/Setup/Setup/Start successfully because you have SetupController and Start action method under Setup Area.

Based on your comment, you want the following url patterns

http://{host}/Setup/‌​{view}
http://{host}/Admin/‌​{view}

You can accomplish that without using any Area. You only need AdminController and SetupController using the default route.

ekad
  • 14,436
  • 26
  • 44
  • 46