Question

Today I spent a good three hours trying to convert the project MvcContrib.Samples.InputBuilders, included in MVC Contrib to make it work with Spark View Engine, but so far was unable to do so.

Does anybody have a clue why these two just won't get along?

Changes I've made

InputForm.spark:

<viewdata model="SampleInput" />
!{Html.InputForm()}

Global.asax.cs:

...
protected void Application_Start() {
    RegisterRoutes(RouteTable.Routes);
    InputBuilder.BootStrap();
    ViewEngines.Engines.Clear();
    ViewEngines.Engines.Add(new SparkViewFactory());
}

Web.config:

...
<spark>
    <compilation debug="true"/>
    <pages automaticEncoding="true">
        <namespaces>
            <add namespace="System"/>
            <add namespace="System.Collections.Generic"/>
            <add namespace="System.Linq"/>
            <add namespace="System.Web.Mvc"/>
            <add namespace="System.Web.Mvc.Ajax"/>
            <add namespace="System.Web.Mvc.Html"/>
            <add namespace="System.Web.Routing"/>
            <add namespace="MvcContrib.UI.InputBuilder"/>
            <add namespace="MvcContrib.UI.InputBuilder.Views"/>
            <add namespace="Web.Models"/>
        </namespaces>
    </pages>
</spark>

(I copied the last three namespaces from the sample project.)

Errors I'm getting

Depending on the order in which I setup Spark/InputBuilder in Global.asax.cs, I get two different exceptions.

If I first setup InputBuilder, then Spark (code shown above):

error CS1061: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'InputForm' and no extension method 'InputForm' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)

If I first setup Spark, then InputBuilder:

The view 'InputForm' or its master could not be found. The following locations were searched:

~/Views/Home/InputForm.aspx

~/Views/Shared/InputForm.aspx

~/Views/InputBuilders/InputForm.aspx

~/Views/Home/InputForm.ascx

~/Views/Shared/InputForm.ascx

Was it helpful?

Solution

Change input.spark to:

<use namespace="MvcContrib.UI.InputBuilder"/>
<use namespace="MvcContrib.UI.InputBuilder.Views"/>
<add namespace="Web.Models"/>
<viewdata model="SampleInput" />
!{Html.InputForm()}

Adding to web.config doesn't work in Spark. You can use _global.spark instead.

There is also another problem. In stable Spark, SparkView Html property is of type HtmlHelper, not HtmlHelper<TModel>. Html.InputForm() function works only for HtmlHelper<TModel>, so you will have to download Spark source and use development build, because it was changed recently. You can also download stable sources and change it yourself. Here is some info:

http://groups.google.com/group/spark-dev/browse_thread/thread/618bd44a94368d22/f7df24e52924f4dc?show_docid=f7df24e52924f4dc

OTHER TIPS

Your on the right track with setting up the input builders and then the spark view engine. You can see from the source file from mvccontrib that you need this namespace defined MvcContrib.UI.InputBuilder.Views for your view to reference the input builders HtmlHelper Extentions.

http://github.com/mvccontrib/MvcContrib/blob/master/src/MVCContrib/UI/InputBuilder/Views/HtmlExtensions.cs

I wrote the input builders but I do not know enough about the spark view engine to know why it is not resolving the reference to the extention methods for the input builders.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top