Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC4 hosting views from other MVC project
    primarykey
    data
    text
    <p>I am attempting to figure out how to host MVC4 apps that were built under different solutions. There are many examples of doing this on SO and on the web using the RazorGenerator nuget package with Areas - it works very well. In my situation, I want to avoid using areas - every application my company develops will be in it's own MVC4 project (then collectively in the same solution). </p> <p>I've integrated RazorGenerator into my apps, the code gen is working as expected. However, my host solution can not find the View in it's default locations. As an example, I have a Controller/View built in one app called MyAccount/Index.</p> <p>Controller:</p> <pre><code>namespace Accounts.Controllers { public class MyAccountController : Controller { // // GET: /MyAccount/ public ActionResult Index() { return View(); } } } </code></pre> <p>View (as generated from RazorGenerator):</p> <pre><code>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&lt;dynamic&gt; { public Index() { } public override void Execute() { #line 1 "..\..\Views\MyAccount\Index.cshtml" ViewBag.Title = "Index"; #line default #line hidden WriteLiteral("\r\n\r\n&lt;h2&gt;Index&lt;/h2&gt;\r\n\r\nMy AccountController Index view."); } } } </code></pre> <p>I know that by default, the ViewEngines are going to try to find this view in the default locations (Views and Shared), so I added my own ViewEngine to the Engines collection:</p> <p>MyViewEngine.cs:</p> <pre><code> public class MyViewEngine : RazorViewEngine { private static string[] _viewLocations = new string[] { "~/Accounts/Views/{1}/{0}.cshtml" }; public MyViewEngine() { base.ViewLocationFormats = ViewLocationFormats.Union(_viewLocations).ToArray(); } } </code></pre> <p>However, the view still isn't found:</p> <pre><code>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 </code></pre> <p>Maybe I am misunderstanding how the view is located -I had thought it would have been found in Accounts/Views/MyAccount/. Any ideas what I might be doing wrong?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload