Andrew Rea - A Developer On A Few Platforms

C#, JAVA, ASP.NET, C++, ACTION SCRIPT

ASP.NET MVC 2 : The view 'Index' or its master was not found

Posted in .NET, ASP.NET MVC, C# by Andrew Rea on 3/14/2010 6:48:31 AM - CST

I was literally setting a new project yesterday to have a play with the released version of ASP.NET MVC 2 and came across a subtle couple of things which when you know, like everything, is easy.

I am creating a small test application which is another blog one, but this time I also want to use an Object DB or many, the first being MONGO, but anyway.  I added a new Area to my project being the Blog area, added the controller and a view and hit F5.

The view 'Index' or its master was not found. The following locations were searched:

Because my area was called Blog, naturally I want the controller to be called BlogController.  The cause and the solution are inside the AreaRegistration file.  When you create your new area you should notice your default route inside this registration file and notice there is no default controller specified, which is correct because at time of creation you will not have a controller inside the area.


        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "Blog_default",
                "Blog/{controller}/{action}/{id}",
                new { action = "Index", id = "" }
            );
        }

 

So add in the default controller and everything is back to normal.  Also, if you do not add this controller and for example add a break point to the return View() of the Index Action on your controller, you will see that it does get hit, it is just the locating of the View which fails.  I am sure there is more plumbing that can be done to enable the location of these views without explicitly stating the default controller but at time of writing I do not know. 


        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "Blog_default",
                "Blog/{controller}/{action}/{id}",
                new {controller="Blog", action = "Index", id = "" }
            );
        }

Cheers for now,

Andrew

Comments

None.

Add Comment

Login using
Google Yahoo flickr AOL
and more
Or provide your details
Please enter your name. Please enter a valid email. Please enter a valid website.
Please supply a comment.
© Copyright 2010 Powered by AtomSite 1.4.0.0