从其他MVC项目MVC4托管意见 [英] MVC4 hosting views from other MVC project

查看:180
本文介绍了从其他MVC项目MVC4托管意见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何承载了不同的解决方案内置MVC4应用。上有SO和使用RazorGenerator的NuGet包区在网络上这样的例子很多 - 它工作得很好。在我的情况,我要避免使用领域 - (在同一个解决方案,然后集体)所有的应用我公司开发的将是它自己的MVC4项目。

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).

我已经集成到RazorGenerator我的应用程序中,code根按预期工作。然而,我的主机解决方案无法找到它的默认位置查看。举个例子,我有建在一个应用程序控制器/视图叫我的帐户/索引。

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.

控制器:

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

查看(从R​​azorGenerator生成):

View (as generated from 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的发动机系列:

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:

MyViewEngine.cs:

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

不过,鉴于仍没找到:

However, the view still isn't found:

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

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

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?

谢谢!

推荐答案

找到了我的问题 - 这是由于没有到位RazorGeneratorMvcStart热身code。当您添加的NuGet包它会自动生成到App_Start文件夹,但是,我错误地删除它。

Found my issue - it was due to not having the RazorGeneratorMvcStart warmup code in place. It is generated automatically into the App_Start folder when you add the nuget package, however I erroneously removed it.

这篇关于从其他MVC项目MVC4托管意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆