2012-01-30 44 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