I'm working on setting up separate projects for my Areas in my main MVC project. I followed the guide here:
https://stackoverflow.com/a/12912161/155110
I set breakpoints during the launch and can see that the RazorGeneratorMvcStart is being hit as well as the AreaRegistration that sets up the routes. RazorGenerator.Mvc is installed and the Custom Tool on my cshtml pages is set to use it. When I access the Area URL after launching my main project, I can see that it hits the controller in the separate Area project, however, I cannot get it to find the view. I get the following which a huge list of locations:
[InvalidOperationException: The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
STARAreaRegistration.cs
using System.Web.Mvc;
namespace AreaSTAR.Areas.STAR
{
public class STARAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "STAR";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"STAR_default",
"STAR/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
}
}
RazorGeneratorMvcStart.cs
using System.Web;
using System.Web.Mvc;
using System.Web.WebPages;
using RazorGenerator.Mvc;
[assembly: WebActivatorEx.PostApplicationStartMethod(typeof(AreaSTAR.RazorGeneratorMvcStart), "Start")]
namespace AreaSTAR {
public static class RazorGeneratorMvcStart {
public static void Start() {
var engine = new PrecompiledMvcEngine(typeof(RazorGeneratorMvcStart).Assembly) {
UsePhysicalViewsIfNewer = HttpContext.Current.Request.IsLocal
};
ViewEngines.Engines.Insert(0, engine);
// StartPage lookups are done by WebPages.
VirtualPathFactoryManager.RegisterVirtualPathFactory(engine);
}
}
}
Areas/STAR/Controllers/DefaultController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace AreaSTAR.Areas.STAR.Controllers
{
public class DefaultController : Controller
{
// GET: STAR/Default
public ActionResult Index()
{
return View();
}
}
}
Areas/STAR/Views/Default/Index.cshtml:
@* Generator: MvcView *@
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>View1</title>
</head>
<body>
<div>
Index view
</div>
</body>
</html>
URL accessed when seeing the View not found error: http://localhost:53992/STAR/Default/Index