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" />