gpt4 book ai didi

c# - Nustache View 引擎 ArrayTypeMismatchException

转载 作者:太空狗 更新时间:2023-10-29 23:47:36 25 4
gpt4 key购买 nike

尝试使用 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.53.回到Solution Explorer,删除Nustache.Mv3中References下的System.Web和System.Web.Mvc4. 右击References 并为System.Web 和System.Web.Mvc 添加版本4.0

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com