c# - Nustache View 引擎 ArrayTypeMismatchException

标签 c# .net asp.net-mvc-3 mustache viewengine

尝试使用 Nustache 来共享客户端和服务器 mustache 模板,但 Nustache 与我的应用程序配合不佳。我在源代码中直接使用了他们的 MVC 应用程序示例中的代码,但每次我尝试设置或添加 View 引擎时都会收到错误消息。这是一个代码片段(来自一个 Action 方法,我也尝试在 global.asax 中全局添加 View 引擎并且有同样的错误):

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
   ...

最佳答案

我将 MVC4 与 Nustache 一起使用,我遇到了完全相同的问题。我花了一段时间才弄清楚这个问题,但我在网上找不到任何解决方案,所以我想我会发布我的解决方案,希望能帮助其他人。

问题是 Nustache.Mvc3 项目引用了 MVC3 中的 System.Web 和 System.Web.Mvc,所以我不得不更新它们以使用 MVC4。要做到这一点: 1. 在 Visual Studio 中,右键单击 Nustache.Mvc3 项目并选择属性 2.在Applicaiton选项卡中,将Target Framework更改为.Net Framework 4.5 3.回到Solution Explorer,删除Nustache.Mv3中References下的System.Web和System.Web.Mvc 4. 右击References 并为System.Web 和System.Web.Mvc 添加版本4.0

关于c# - Nustache View 引擎 ArrayTypeMismatchException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9066478/

相关文章:

c# - 使用.NET读取oracle表,一个LONG类型的列总是返回空字符串,如何解决?

asp.net-mvc - 获取记录时出错 "LINQ to Entities does not recognize the method"

c# - "Request entity too large"和锁定的配置部分

c# - 子类的条件验证

c# - 如何在 Flurl 中使用代理进行 Web 请求?

c# - 如何使用 C# 中的 struct 提供显示为 info 的数据?

javascript - MVC-Mini-Profiler 错误 : yepnope is not defined

c# - 抛出异常时是否应该省略 else 语句?

c# - 捕获程序的每个异常?

.net - 登录 API