2016-08-25 78 views
1

我正在爲我的主要MVC項目中的區域設置單獨的項目。我跟着指南這裏:MVC單獨區域項目 - 無法找到視圖

https://stackoverflow.com/a/12912161/155110

我期間推出設置斷點,可以看到RazorGeneratorMvcStart正在熱播,以及,設置了路由的AreaRegistration。 RazorGenerator.Mvc已安裝,我的cshtml頁面上的自定義工具已設置爲使用它。當我啓動我的主項目後訪問區域URL時,我可以看到它在單獨的Area項目中擊中了控制器,但是我無法找到該視圖。我得到其下面的位置的巨大的名單:

[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); 
     } 
    } 
} 

地區/ STAR /控制器/ 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/S TAR /瀏覽/預設/ 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眼看查看沒有發現錯誤時訪問:http://localhost:53992/STAR/Default/Index

回答

1

這是因爲我不小心安裝了RazorEngine.Generator擴展和設置自定義工具RazorEngineGenerator而不是安裝Razer Generator擴展並將自定義工具設置爲RazorGenerator。