2013-04-26 57 views
4

我试图找出如何托管在不同的解决方案下构建的MVC4应用程序。在SO和网上使用RazorGenerator nuget包进行这些操作的例子很多 - 它工作得很好。在我的情况下,我想避免使用区域 - 我公司开发的每个应用程序都将在它自己的MVC4项目中(然后统一在同一个解决方案中)。MVC4托管从其他MVC项目的意见

我已经将RazorGenerator集成到我的应用程序中,代码gen按预期工作。但是,我的主机解决方案在默认位置找不到视图。举个例子,我有一个名为MyAccount/Index的应用程序构建的Controller/View。

控制器:

namespace Accounts.Controllers 
{ 
    public class MyAccountController : Controller 
    { 
     // 
     // GET: /MyAccount/ 
     public ActionResult Index() 
     { 
      return View(); 
     } 
    } 
} 

图(从RazorGenerator生成):

namespace Accounts.Views.MyAccount 
{ 
    using System; 
    using System.Collections.Generic; 
    using System.IO; 
    using System.Linq; 
    using System.Net; 
    using System.Text; 
    using System.Web; 
    using System.Web.Helpers; 
    using System.Web.Mvc; 
    using System.Web.Mvc.Ajax; 
    using System.Web.Mvc.Html; 
    using System.Web.Routing; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.WebPages; 

    [System.CodeDom.Compiler.GeneratedCodeAttribute("RazorGenerator", "1.5.4.0")] 
    [System.Web.WebPages.PageVirtualPathAttribute("~/Views/MyAccount/Index.cshtml")] 
    public partial class Index : System.Web.Mvc.WebViewPage<dynamic> 
    { 
     public Index() 
     { 
     } 
     public override void Execute() 
     { 

      #line 1 "..\..\Views\MyAccount\Index.cshtml" 

    ViewBag.Title = "Index"; 


      #line default 
      #line hidden 
WriteLiteral("\r\n\r\n<h2>Index</h2>\r\n\r\nMy AccountController Index view."); 

     } 
    } 
} 

我知道,在默认情况下,该ViewEngines将试图找到默认位置这一观点(查看和共享),所以我将我自己的ViewEngine添加到引擎集合中:

MyViewEngine.cs:

public class MyViewEngine : RazorViewEngine 
    { 
     private static string[] _viewLocations 
      = new string[] 
      { 
       "~/Accounts/Views/{1}/{0}.cshtml" 
      }; 

     public MyViewEngine() 
     { 
      base.ViewLocationFormats = ViewLocationFormats.Union(_viewLocations).ToArray(); 
     } 
    } 

但是,鉴于仍然没有找到:

The view 'Index' or its master was not found or no view engine supports the searched locations. 
The following locations were searched: 
~/Views/MyAccount/Index.cshtml 
~/Views/Shared/Index.cshtml 
~/Views/MyAccount/Index.aspx 
~/Views/MyAccount/Index.ascx 
~/Views/Shared/Index.aspx 
~/Views/Shared/Index.ascx 
~/Views/MyAccount/Index.vbhtml 
~/Views/Shared/Index.vbhtml 
~/Accounts/Views/MyAccount/Index.cshtml 

也许我误解的观点是如何定位 - 我原以为它会在帐户被发现/浏览/我的帐户/。任何想法我可能做错了什么?

谢谢!

回答

1

发现我的问题 - 这是由于没有RazorGeneratorMvcStart预热代码。当你添加nuget包时,它会自动生成到App_Start文件夹中,但是我错误地删除了它。