外部剃刀意见不能看到外部模型 [英] External razor views can't see external models

查看:97
本文介绍了外部剃刀意见不能看到外部模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有外部剃刀意见的问题。
在项目中,我有自己的控制器,视图和模型主要的MVC Web组件和动态加载外部类库组件(从DB)。这些程序集不直接引用,并在运行时加载。

我能够通过创建控制器自定义控制器工厂,用于查看自定义虚拟路径提供,使整个系统的工作。该观点被嵌入资源,我的外部组件。

我的问题是,当我创建了一个强类型的外部景观与外部程序集的观点不能在运行时编译一个模型类,因为该组件不会传递到剃须刀编译器。所以,我得到以下错误:


  

编译器错误信息:CS0234:类型或命名空间名称
  为myplugin'不命名空间中存在'myNameSpace对象(是缺少程序
  集引用?)


  
  

源错误:


 公共类
_Page_ExternalViews_MyController_MyAction_cshtml:System.Web.Mvc.WebViewPage< MyNamespace.MyPlugin.Models.MyModel>
{

当我使用一个动态模型,模型类从我的主要网络组件或者直接在我的web项目中引用的程序,它工作正常。我知道肯定外部剃须刀意见之前编制的外部组件加载,因为我的控制器工作得很好。

我开始寻找在RazorGenerator项目precompile我的外部意见,但未能取得任何进展(正在生成什么),我甚至不知道我期待在正确的方向,因为我的组件在运行时加载,我必须用我自己的ViewEngine和的ControllerFactory。


解决方案

我能够与RazorGenerator的Visual Studio扩展(而不是 RazorGenerator.Mvc 一个precompile意见)在我的组件。

它基本上 .cshtml 剃须刀意见转换成的.cs 文件, WebViewPage 组件编译之前类。
而在我的网站项目,我必须实现我自己的 VirtualPathProviderViewEngine 类似<一个href=\"http://www.symbolsource.org/Public/Metadata/NuGet/Project/$p$pcompiledMvcViewEngine/1.0/Release/.NETFramework,Version=v4.0/$p$pcompiledMvcViewEngine/$p$pcompiledMvcViewEngine/$p$pcompiledMvcEngine.cs?ImageName=$p$pcompiledMvcViewEngine\"相对=nofollow>这个

I have a problem with external razor views. In my project I have main mvc web assembly and dynamically loaded external class library assemblies(from DB) with their own Controllers, Views and Models. These assemblies are not directly referenced and loaded at runtime.

I was able to make the whole system work by creating a custom controller factory for Controllers, a custom virtual path provider for Views. The views are embedded resources in my external assemblies.

The problem I have is when I create a strongly-typed external View with a model class from an external assembly the view cannot be compiled at runtime, because the assembly is not passed to the razor compiler. So I get the following error:

Compiler Error Message: CS0234: The type or namespace name 'MyPlugin' does not exist in the namespace 'MyNamespace' (are you missing an assembly reference?)

Source Error:

public class
_Page_ExternalViews_MyController_MyAction_cshtml : System.Web.Mvc.WebViewPage<MyNamespace.MyPlugin.Models.MyModel>
{

It works fine when I use a dynamic model, a model class from my main web assembly or from assemblies referenced directly in my web project. I know for sure that external assembly is loaded before the external razor views are compiled, since my controllers work just fine.

I started looking at RazorGenerator project to precompile my external Views, but wasn't able to make any progress (nothing is being generated) and I'm not even sure if I'm looking in the right direction, since my assemblies are loaded at runtime and I have to use my own ViewEngine and ControllerFactory.

解决方案

I was able to precompile views with RazorGenerator Visual Studio extension (not RazorGenerator.Mvc one) in my assemblies.

It basically converts .cshtml razor views into .cs files with WebViewPage classes before assemblies compile. And in my web project I had to implement my own VirtualPathProviderViewEngine similar to this one

这篇关于外部剃刀意见不能看到外部模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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