mmu*_*rch 5 .net c# viewengine mustache asp.net-mvc-3
尝试使用Nustache来共享客户端和服务器胡子模板,但Nustache只是不能很好地使用我的应用程序.我在源代码中直接使用了他们的MVC应用程序示例中的代码,但每次尝试设置或添加视图引擎时都会出错.这是一个代码片段(来自一个动作方法,我也试过在global.asax中全局添加视图引擎并且有相同的错误):
ViewResult viewResult = View(new { test = "Jawesome" });
viewResult.ViewEngineCollection = new ViewEngineCollection
{
new NustacheViewEngine()
};
Run Code Online (Sandbox Code Playgroud)
这是错误:
[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
...
Run Code Online (Sandbox Code Playgroud)
我正在使用 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。 Nustache.Mv3 中的 References 下的 Web.Mvc 4. 右键单击 References 并为 System.Web 和 System.Web.Mvc 添加版本 4.0