2011-08-03 32 views
1

我已經開始使用MvcContrib的便攜式區域,並且對於非常簡單的視圖,一切正常,但是當我想要在我的視圖中使用自定義模型時,我會看到表示命名空間不存在的錯誤。ASP.NET MVC 3 - 便攜式區域視圖找不到我的模型

視圖設置爲嵌入資源。在視圖中的intellisense認可模型就好了。

有沒有人有任何想法可能會導致問題?

UPDATE

我想可能有這樣的事實,我使用MEF加載插件做。加載控制器時,我遇到了類似的問題。如果默認controllerfactory沒有找到合適的控制器,我必須構建一個自定義的ControllerFactory,它將查看MEF控制器列表。

更新2

我設法通過提供RazorBuildProvider我MEF加載組件擺脫錯誤的。但是,現在看不到了。如果視圖不是強類型的,就會找到它。

RazorBuildProvider.CodeGenerationStarted += (object sender, EventArgs e) => 
    { 
     RazorBuildProvider provider = (RazorBuildProvider)sender; 
     foreach (var module in ExternalComponents) 
     { 
      provider.AssemblyBuilder.AddAssemblyReference(module.GetType().Assembly); 
     } 
    }; 

源代碼

示範

namespace Isis.Plugins.TextArea.TextArea.Models 
{ 
    public class TextAreaModel 
    { 
     [Required(ErrorMessage = "Field is required")] 
     public string Message { get; set; } 
    } 
} 

控制器:

namespace Isis.Plugins.TextArea.TextArea.Controllers 
{ 
    [Export(typeof(IController))] 
    public class IndexController : Controller 
    { 
     [HttpGet] 
     public ActionResult Index() 
     { 
      return View(new TextAreaModel() { Message = "Hallow!" }); 
     } 

     [HttpGet] 
     public ActionResult Editor() 
     { 
      return View(new TextAreaModel() { Message = "EDITOR CONTENT" }); 
     } 
    } 
} 

@model Isis.Plugins.TextArea.TextArea.Models.TextAreaModel 

@Model.Message 

錯誤:

Compilation Error 

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

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

Source Error: 


Line 27:  
Line 28:  
Line 29:  public class _Page_Areas_TextArea_Views_Index_Index_cshtml : System.Web.Mvc.WebViewPage<Isis.Plugins.TextArea.TextArea.Models.TextAreaModel> { 
Line 30:   
Line 31: #line hidden 

回答

0

我最終決定將在Bin目錄,而不是一個自定義的插件目錄中的所有插件。這不是我所瞄準的解決方案,但它現在起作用。

1

我正面臨類似的問題,MEF &剃鬚刀視圖引擎(嘗試類似的方法,你已經描述過)。當我加載我的強類型剃刀視圖時,我得到「你是否缺少裝配/參考」錯誤。

我試着在Bin下部署我的程序集,但這也沒有幫助。

避免它的唯一方法是在RazorBuildProvider上執行loadFrom程序集。

我找不到比其他的RazorBuildProvider任何文件「不適合直接在代碼中使用

你的代碼片段是挺有意思的......你能解釋一下它是如何工作的?預計在哪裏註冊 - 在AppStart上?

RazorBuildProvider.CodeGenerationStarted += (object sender, EventArgs e) => 
{ 
    RazorBuildProvider provider = (RazorBuildProvider)sender; 
    foreach (var module in ExternalComponents) 
    { 
     provider.AssemblyBuilder.AddAssemblyReference(module.GetType().Assembly); 
    } 
}; 

任何清晰度將不勝感激......