我試圖找出如何託管在不同的解決方案下構建的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
也許我誤解的觀點是如何定位 - 我原以爲它會在帳戶被發現/瀏覽/我的帳戶/。任何想法我可能做錯了什麼?
謝謝!