asp.net – 来自其他MVC项目的MVC4托管视图
发布时间:2020-12-16 09:38:53 所属栏目:asp.Net 来源:网络整理
导读:我试图弄清楚如何托管在不同解决方案下构建的MVC4应用程序.有许多使用带有区域的RazorGenerator nuget包在SO和Web上执行此操作的示例 – 它非常有效.在我的情况下,我想避免使用区域 – 我公司开发的每个应用程序都将在它自己的MVC4项目中(然后集中在同一个解
我试图弄清楚如何托管在不同解决方案下构建的MVC4应用程序.有许多使用带有区域的RazorGenerator nuget包在SO和Web上执行此操作的示例 – 它非常有效.在我的情况下,我想避免使用区域 – 我公司开发的每个应用程序都将在它自己的MVC4项目中(然后集中在同一个解决方案中).
我已将RazorGenerator集成到我的应用程序中,代码生成正如预期的那样.但是,我的主机解决方案无法在其默认位置找到View.例如,我在一个名为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 "....ViewsMyAccountIndex.cshtml" ViewBag.Title = "Index"; #line default #line hidden WriteLiteral("rnrn<h2>Index</h2>rnrnMy AccountController Index view."); } } } 我知道默认情况下,ViewEngines会尝试在默认位置(Views和Shared)中查找此视图,因此我将自己的ViewEngine添加到Engines集合中: 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 也许我误解了视图的位置 – 我以为它会在Accounts / Views / MyAccount /中找到.我有什么想法可能做错了吗? 谢谢! 解决方法
发现我的问题 – 这是由于没有使用RazorGeneratorMvcStart预热代码.添加nuget包时,它会自动生成到App_Start文件夹中,但是我错误地删除了它.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – ASP.NET MVC中的静态文件路由
- asp.net-mvc – ASP.NET Webforms或ASP.NET MVC中的电子商务
- 有没有办法将一个onclick事件添加到ASP.NET标签服务器控件?
- asp.net-mvc – 如何使用MVC调用JQuery UI模式(CRUD)
- asp.net-mvc – 如何测试我的Web应用程序是否可以处理大量流
- asp.net – Application_EndRequest没有找到Session
- asp-classic – 如何在asp页面中以编程方式301重定向?
- asp.net中使用Page.Validate()和Page.IsValid进行服务器端验
- asp经典 – ASP Classic中的注释代码
- 如何最好地生成CSV(逗号分隔的文本文件)以便下载ASP.NET?
推荐文章
站长推荐
- asp.net-mvc – 处理asp.net mvc中的错误和异常
- asp.net-core – 如何将安全更新应用于.NET Core
- asp.net – 使用Rake创建IIS网站
- asp.net-mvc – 使用cshtml页面的angularjs不是带
- asp.net – 下拉列表中的重复项目!
- ASP.NET(MVC)Outputcache和并发请求
- asp.net-web-api – ODataConventionModelBuilde
- 如何将成员资格表与实体框架集成? Asp.net
- asp.net – HttpCookieCollection.Add和HttpCook
- asp.net-mvc-3 – 显示modelstate错误
热点阅读