相关疑难解决方法(0)

使用VirtualPathProvider从DLL加载ASP.NET MVC视图

基于这个问题,在这里和使用代码发现在这里,我试图加载嵌入资源在一个单独的DLL项目的意见,原来的问题的作者说,他已成功这样做-但我不能把它作为工作似乎MVC视图引擎正在拦截请求,仍然在查看视图的文件系统.例外:

Server Error in '/' Application.
The view 'Index' or its master could not be found. The following locations were searched:
~/Views/admin/Index.aspx
~/Views/admin/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/App/Views/admin/Index.aspx
~/App/Views/admin/Index.ascx
~/App/Views/Shared/Index.aspx
~/App/Views/Shared/Index.ascx 
Run Code Online (Sandbox Code Playgroud)

我使用的是CustomViewEngine像Rob Connery的/ App结构,如下所示:

public class CustomViewEngine : WebFormViewEngine
    {
         public CustomViewEngine()
         {
             MasterLocationFormats = new[] { 
                "~/App/Views/{1}/{0}.master", 
                "~/App/Views/Shared/{0}.master" 
                };

             ViewLocationFormats = new[] { 
                "~/App/Views/{1}/{0}.aspx", 
                "~/App/Views/{1}/{0}.ascx", 
                "~/App/Views/Shared/{0}.aspx", 
                "~/App/Views/Shared/{0}.ascx" 
                };

             PartialViewLocationFormats = ViewLocationFormats;
         }
    }
Run Code Online (Sandbox Code Playgroud)

这是我的路线:

    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute("Home", "", new {controller = "Page", action = "Index", id …
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-mvc virtualpathprovider

40
推荐指数
1
解决办法
3万
查看次数

ASP.NET MVC从数据库加载Razor视图

ScottGu提到我们应该能够从数据库加载一个Razor视图(查看评论部分),那么有没有人有一个如何做到这一点的例子?

谢谢.

asp.net-mvc razor

20
推荐指数
1
解决办法
2万
查看次数

ASP.NET MVC 3.0 Razor,从开箱即用的任何地方加载View?

是否可以在任何地方加载View而无需VirtualPathProvider在MVC 3.0中实现自定义?

如果是真的怎么办?

实际上VirtualPathProvider,从任何地方加载View 都没有问题,但是我的实现仅在MVC 2.0中工作,而不是用MVC 3.0工作,因为某些原因GetFile在MVC 3.0中新的调用不存在的视图,在这种情况下,我是得到" Server Error in '/' Application."

VirtualPathProvider从这里按照相同的代码为我的自定义:http://buildstarted.com/2010/09/28/mvc-3-razor-view-engine-without-a-controller/

更新1

好吧,我VirtualPathProvider把我的自定义VirtualPathProvider提供程序第一行的注册放在Application_Start()中 后,我确实修复了我的自定义问题

    protected void Application_Start()
    {
        //Should be first line before routes and areas registration.
        HostingEnvironment.RegisterVirtualPathProvider(new MyVirtualPathProvider());

        AreaRegistration.RegisterAllAreas();

        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);
    }
Run Code Online (Sandbox Code Playgroud)

Global.asax.cs后面AreaRegistration.RegisterAllAreas();RegisterRoutes(RouteTable.Routes);方法方法中注册自定义VirtualPathProvider时override VirtualFile GetFile(string virtualPath),"虚拟视图"不适用.

更新2

这是否意味着课程RazorViewRazorViewEngineRender答案?

更新3

如果我有我的剃刀视图的字符串表示在文件系统中不存在(例如我在数据库中存储剃刀视图)我怎样才能使用这种方法呈现它http://buildstarted.com/2010/09/28/ MVC -3-剃刀-视图-发动机而不-A-控制器/

例如,我的View的字符串表示如下所示:

"@{
    ViewBag.Title = ""About …
Run Code Online (Sandbox Code Playgroud)

razor asp.net-mvc-3

12
推荐指数
2
解决办法
1万
查看次数

ASP.net MVC:从DB String执行Razor?

我正在考虑让最终用户能够将部分视图(控件)放入存储在数据库中的信息中.有没有办法执行我从数据库中获取的字符串作为Razor视图的一部分?

sql asp.net-mvc asp.net-mvc-partialview razor

6
推荐指数
1
解决办法
2304
查看次数