I have tried emptying the entire file part by part and nothing seems to help. If I create a controller and view outside the area it works just fine. If I create an aspx view it works fine as well. Is it possible the default razor view engine doesn't support areas at this time?
The areas are registered too.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Random", action = "Index", id = UrlParameter.Optional }
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"SomeArea_default",
"SomeArea/{controller}/{action}/{id}",
new { controller = "List", action = "Index", id = UrlParameter.Optional }
);
}
I think it should work becuse both WebFormViewEngine and CshtmlViewEngine are inherited from VirtualPathProviderViewEngine which have Same FindView Method.
According your Error, it shows that only WebFormViewEngine is used.
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Marked as answer by aarondl on Aug 23, 2010 08:06 PM
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
AaronDL
Member
1 Points
6 Posts
ASP.NET MVC3 Areas and Razor views produce errors?
Aug 22, 2010 07:31 PM|LINK
The view at '~/Areas/SomeArea/Views/List/Index.cshtml' must derive from ViewPage, ViewPage, ViewUserControl, or ViewUserControl.
The project structure is pretty much default. There is one area called SomeArea. It has a single controller called List. It does nothing except:
public ActionResult Index() { return View("~/Areas/SomeArea/Views/List/Index.cshtml"); }The view looks like:
@inherits System.Web.Mvc.WebViewPage<dynamic> @{ View.Title = "Index"; LayoutPage = "~/Views/Shared/_Layout.cshtml"; }asp .net mvc3 razor areas
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: ASP.NET MVC3 Areas and Razor views produce errors?
Aug 23, 2010 07:00 PM|LINK
I think it should work becuse both WebFormViewEngine and CshtmlViewEngine are inherited from VirtualPathProviderViewEngine which have Same FindView Method.
According your Error, it shows that only WebFormViewEngine is used.
Try,
return View(new CshtmlView("~/Areas/SomeArea/Views/List/Index.cshtml"));
For WebForm View Try,
return View(new WebFormView("~/Areas/SomeArea/Views/List/Index.aspx"));
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
AaronDL
Member
1 Points
6 Posts
Re: ASP.NET MVC3 Areas and Razor views produce errors?
Aug 23, 2010 08:06 PM|LINK
That did the trick thanks a lot!
Is there anyway to set Razor to be the default view engine so this problem won't occur if Razor is all I'm using?
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: ASP.NET MVC3 Areas and Razor views produce errors?
Aug 23, 2010 11:37 PM|LINK
Add this in Application_Start
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new CshtmlViewEngine());
ViewEngines.Engines.Add(new WebFormViewEngine());
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD