2012-01-30 75 views
5

試圖使用Nustache共享客戶端和服務器鬍鬚模板,但Nustache只是不能很好地與我的應用程序一起玩。我直接從源代碼中的MVC應用程序示例中使用代碼,但每次嘗試設置或添加視圖引擎時都會出現錯誤。下面是一個代碼片段(來自一個操作方法,我也試着在Global.asax中添加全局視圖引擎,並有同樣的錯誤):Nustache查看引擎ArrayTypeMismatchException

ViewResult viewResult = View(new { test = "Jawesome" }); 

viewResult.ViewEngineCollection = new ViewEngineCollection 
            { 
             new NustacheViewEngine() 
            }; 

而這裏的錯誤:

[ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.] 
    System.Collections.Generic.List`1.Insert(Int32 index, T item) +62 
    MyController.Index() in C:\src\projects\myproject\myproject.Web\Controllers\MyController.cs:83 
    lambda_method(Closure , ControllerBase , Object[]) +79 
    System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +264 
    ... 

回答

-1

不再是一個問題,現在可以正常工作。抱歉!

+1

您是如何解決這個問題的? – 2012-03-03 15:24:08

+0

這不是一個答案... – 2015-12-20 22:53:19

1

我使用MVC4與Nustache和我有完全相同的問題。我花了一段時間才弄清楚這個問題,我在網上找不到任何解決方案,所以我想我會發布我的解決方案,希望幫助別人。

問題是Nustache.Mvc3項目引用MVC3中的System.Web和System.Web.Mvc,所以我必須更新它們才能使用MVC4。爲此,請執行以下操作: 1.在Visual Studio中,右鍵單擊Nustache.Mvc3項目,然後選擇屬性 2.在應用程序選項卡中,將目標框架更改爲.Net Framework 4.5 3.返回到解決方案資源管理器,刪除System.Web和System.Web.Mvc在Nustache.Mv3中的引用下4.右鍵單擊引用併爲System.Web和System.Web.Mvc添加版本4.0