Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 3 - New Area - 404 error - Resource not found - have tried route debugger

I have a small MVC 3 app - bit of a demo ground. I have one area and thats been working fine.

I have just added another area expecting to just spin up the app and it work - but no, 404 - The resource cannot be found.

The map route in the AreaRegistration is the default (as is the first area i created).

public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "Postcard_default",
            "Postcard/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional }
        );
    }

I have tried adding in a specific controller into this, but nothing.

So I downloaded Phil Haack's RouteDebugger and my route is found when typing in http://server/Postcard/Create (which is where I am trying to get too)

Structure of the Area

alt text

My controller

    public class CreateController : Controller
{
    private ILogger Logger { get; set; }
    private ICardSender Emailer { get; set; }
    private IOCCardRepository CardRepository { get; set; }

    public CreateController(ILogger logger, ICardSender cardSender, IOCCardRepository repository)
    {
        this.Logger = logger;
        this.Emailer = cardSender;
        this.CardRepository = repository;
    }


    //
    // GET: /Postcard/Create/

    public ActionResult Index()
    {
        var model = new OCPostcardModel().Create();

        return View(model);
    }

NOW: I have since deleted the entire area, tried again it didn't work. So I added in the specific controller in the route (Inside AreaRegistration file)

context.MapRoute(
            "Postcard_default",
            "Postcard/{controller}/{action}/{id}",
            new { controller = "Create", action = "Index", id = UrlParameter.Optional }
        );

And its working...I don't know why it didn't work when I did this before, but it is now.

Still curious though as I've not seen anyone add in this controller into route in any of the demo's i've looked at - and I haven't got it in my other area?

like image 520
SteveCl Avatar asked Dec 21 '10 14:12

SteveCl


2 Answers

I ran into this when I moved a controller into an Area but forgot to update the namespace. The controller name is scoped to the Area's namespace. So "Some" in "Area" will map to App.Areas.Area.Controllers.SomeController, which didn't exist.

like image 119
jamie Avatar answered Nov 17 '22 00:11

jamie


You were missing the controller part in your maproute

like image 25
Tongayi Avatar answered Nov 17 '22 02:11

Tongayi