使用asp.net MVC 2的功能与火花视图引擎 [英] Using asp.net mvc 2 features with the spark view engine

查看:270
本文介绍了使用asp.net MVC 2的功能与火花视图引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与最初是从<一开始一个ASP.NET MVC项目工作href=\"http://$c$cbetter.com/blogs/karlseguin/archive/2009/04/28/$p$psenting-$c$cbetter-canvas.aspx\">$c$cBetter.Canvas项目 - 和我想要移动到ASP.NET MVC 2。我成功升级使用我的项目的Eilon's升级工具,转移到VS2010(虽然还没有到.NET 4)。

使用火花视图引擎,当我在目前问题只发生。这里是我的View.spark(强类型)code的相关位:

  $ {Html.EditorFor(E =&GT; E)}

code的同位的只是罚款的,如果我用一个.aspx视图:

 &LT;%= Html.EditorFor(E =&GT; E)%GT;

这里的主要观点是EditorFor是ASP.NET MVC 2新在我的项目,我可以使用该助手在一个ASPX视图,但不是星火视图。

我试过<一个href=\"http://stackoverflow.com/questions/1261576/asp-net-mvc-2-0-$p$pv-1-and-spark/1264289#1264289\">upgrading星火使用MVC 2 (以及MvcContrib和Ninject),也许认为它是被吓坏了其中的一个 - 但至今没有运气 - 我仍然看到相同的行为

下面是从星火的BatchCompiler类中抛出的完整的错误消息。


  

动态视图编译失败。
  (0,0):警告CS1701:假设
  集引用'System.Web.Mvc,
  版本= 1.0.0.0,文化=中立,
  公钥= 31bf3856ad364e35'
  匹配'System.Web.Mvc,
  版本= 2.0.0.0,文化=中立,
  公钥= 31bf3856ad364e35',你
  可能需要提供运行时策略
  C:\\的Inetpub \\ wwwroot文件[myproject的] \\ codeBetter.Canvas.Web \\查看[myEntity所] \\ View.spark(9,16):
  错误CS1061:
  System.Web.Mvc.HtmlHelper不
  包含EditorFor的定义
  没有扩展方法'EditorFor
  接受类型的第一个参数
  System.Web.Mvc.HtmlHelper可能是
  (是否缺少using
  指令或程序集引用?)


下面是我的Global.asax星火相关code:

  VAR设置=新SparkSettings()
.AddNamespace(系统)
.AddNamespace(System.Collections.Generic)
.AddNamespace(System.Web.Mvc)
.AddNamespace(System.Web.Mvc.Html)
.AddNamespace(MvcContrib.FluentHtml)
.AddNamespace(codeBetter.Canvas)
.AddNamespace(codeBetter.Canvas.Web)
.SetPageBaseType(ApplicationViewPage)
.SetAutomaticEncoding(真);#如果DEBUG
    settings.SetDebug(真);
#万一VAR的ViewFactory =新SparkViewFactory(设置);
ViewEngines.Engines.Add(的ViewFactory);

此外,我引用System.Web.Mvc.Html我认为火花提到<一个href=\"http://stackoverflow.com/questions/1081650/cannot-use-html-actionlink-in-asp-net-mvc-spark-files\">in另一SO回答。

 &LT;利用空间=System.Web.Mvc.Html/&GT;


解决方案

根本的问题是,1.0.0版本组件仍在某处项目中引用。

使用反射来检查每个组件的依赖,我发现(如果你先从codeBetter.Canvas项目)有需要更新相关项目使用版本2.0.0 System.Web.Mvc.dll程序的


  1. 星火。下载最新版本
    从TeamCity的火花,并使用
    spark.web.mvc2.dll(引用
    System.Web.Mvc.dll程序2.0.0)<一个href=\"http://stackoverflow.com/questions/1261576/asp-net-mvc-2-0-$p$pv-1-and-spark/1264289#1264289\">Link详细说明书。


  2. MVCContrib 。下载最新版本
    MVCContrib(的<一个href=\"http://teamcity.$c$cbetter.com/guestAuth/repository/download/bt81/.lastPinned/MVCContrib.release.zip\"相对=nofollow>下载发布,下载源),它引用
    System.Web.Mvc.dll程序2.0.0。


  3. Ninject 下载最新版本的
    ninject
    并重新编译与解决方案
    更新所述参考2.0.0后
    System.Web.Mvc.dll程序版本


现在,在您的项目替换这些依赖的组件并在必要时更新项目引用。所有应该很好。

I am working with an ASP.NET MVC project which was originally started from the CodeBetter.Canvas project - and I'm trying to move to ASP.NET MVC 2. I successfully upgraded my project using Eilon's upgrade tool, moved to VS2010 (although not yet to .NET 4).

The issue I'm having currently is only occurring when using the spark view engine. Here is the relevant bit of code in my View.spark (strongly typed):

${Html.EditorFor(e => e)}

The same bit of code works just fine if I use an .aspx view:

<%= Html.EditorFor(e => e) %>

The major point here being "EditorFor" is new in ASP.NET MVC 2 and in my project I can use that helper in an ASPX view but not a Spark view.

I've tried upgrading Spark to use MVC 2 (as well as MvcContrib and Ninject), thinking maybe it was one of those that was freaking out - but so far no luck - I'm still seeing the same behavior.

Here is the full error message that is thrown from within Spark's BatchCompiler class.

Dynamic view compilation failed. (0,0): warning CS1701: Assuming assembly reference 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' matches 'System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35', you may need to supply runtime policy c:\inetpub\wwwroot[myproject]\CodeBetter.Canvas.Web\Views[MyEntity]\View.spark(9,16): error CS1061: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'EditorFor' and no extension method 'EditorFor' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)

Here is the Spark related code in my Global.asax:

var settings = new SparkSettings()
.AddNamespace("System")
.AddNamespace("System.Collections.Generic")
.AddNamespace("System.Web.Mvc")
.AddNamespace("System.Web.Mvc.Html")
.AddNamespace("MvcContrib.FluentHtml")
.AddNamespace("CodeBetter.Canvas")
.AddNamespace("CodeBetter.Canvas.Web")
.SetPageBaseType("ApplicationViewPage")
.SetAutomaticEncoding(true);

#if DEBUG
    settings.SetDebug(true);
#endif

var viewFactory = new SparkViewFactory(settings);
ViewEngines.Engines.Add(viewFactory);

Also, I am referencing System.Web.Mvc.Html in my spark view as mentioned in another SO answer.

<use namespace="System.Web.Mvc.Html" />

解决方案

The underlying issue is that a version 1.0.0 assembly is still being referenced somewhere in the project.

Using reflector to examine each assemblies dependencies, I found (if you're starting with CodeBetter.Canvas project) there are three dependent projects that need to be updated to use the 2.0.0 version of system.web.mvc.dll

  1. Spark. Download the latest version of spark from teamcity and use the spark.web.mvc2.dll (which references system.web.mvc.dll 2.0.0) Link to detailed instructions.

  2. MVCContrib. Download the latest version of MVCContrib (download release, download source) which references the system.web.mvc.dll 2.0.0.

  3. Ninject. Download the latest version of ninject and recompile the VS solution after updating the reference to the 2.0.0 version of system.web.mvc.dll

Now, replace these dependency's assemblies in your project and update the project references if necessary. All should be well.

这篇关于使用asp.net MVC 2的功能与火花视图引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆