Nustache 视图引擎 ArrayTypeMismatchException
尝试使用 Nustache 共享客户端和服务器胡子模板,但 Nustache 与我的应用程序配合得不好。我在源代码中直接使用了 MVC 应用程序示例中的代码,但每次尝试设置或添加视图引擎时都会收到错误。这是一个代码片段(来自操作方法,我还尝试在 global.asax 中全局添加视图引擎并出现相同的错误):
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
...
Trying to use Nustache to share client and server mustache templates, but Nustache is just not playing nicely with my app. I used the code straight out of their MVC application example in the source code but am getting an error every time I try to set or add the view engine. Here's a code snippet (from an action method, I've also tried adding the view engine globally in global.asax and had the same error):
ViewResult viewResult = View(new { test = "Jawesome" });
viewResult.ViewEngineCollection = new ViewEngineCollection
{
new NustacheViewEngine()
};
And here's the error:
[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
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在使用 MVC4 和 Nustache,并且遇到了完全相同的问题。我花了一段时间才弄清楚这个问题,而且我在网上找不到任何解决方案,所以我想我会发布我的解决方案,希望能帮助其他人。
问题是 Nustache.Mvc3 项目引用了 MVC3 中的 System.Web 和 System.Web.Mvc,因此我必须更新它们以使用 MVC4。为此:
1. 在 Visual Studio 中,右键单击 Nustache.Mvc3 项目并选择属性
2. 在“应用程序”选项卡中,将“目标框架”更改为“.Net Framework 4.5”
3.返回解决方案资源管理器,删除Nustache.Mv3中References下的System.Web和System.Web.Mvc
4. 右键单击“引用”并为 System.Web 和 System.Web.Mvc 添加版本 4.0
I am using MVC4 with Nustache and I was having the exact same issue. It took me a while to figure out the issue and I couldn't find any solutions on the web so I thought I would post my solution in hopes of helping someone else.
The issue was the Nustache.Mvc3 project was referencing System.Web and System.Web.Mvc from MVC3 so I had to update them to use MVC4. To do that:
1. In Visual Studio, right-click Nustache.Mvc3 project and select Properties
2. In the Applicaiton tab, change Target Framework to .Net Framework 4.5
3. Go back to Solution Explorer, delete System.Web and System.Web.Mvc under References in Nustache.Mv3
4. Right-click References and Add version 4.0 for both System.Web and System.Web.Mvc