Strongly-typed HtmlHelper<T>?

26 views
Skip to first unread message

Tim

unread,
Aug 8, 2009, 7:52:09 AM8/8/09
to Spark View Engine Dev
Hi all,

I know there's an instance of HtmlHelper available in Spark views,
i.e.

${Html.TextBox(...)}

But I'm wondering if the strongly-typed version of HtmlHelper is also
available?

Let's say I've registered my model type:
<viewdata model="MyModelType" />

I'd really like to be able to write the following, but I'm not sure if
it's possible:

${Html.ViewData.Model}

(This is not my actual usage, obviously - my actual usage involves an
extension method on HtmlHelper<T>).

Thanks,
Tim

DeLight

unread,
Aug 29, 2009, 10:49:32 AM8/29/09
to Spark View Engine Dev
No there is no suppert of generic helpers currently.
But it can be added very easily: add appropriate properties in
SparkView<TModel>, refactor virtual void InitHelpers() out of
SparkView.Render() and override it in SparkView<TModel>.
It will be great if it is done in Spark codebase.

Louis DeJardin

unread,
Aug 30, 2009, 11:43:19 PM8/30/09
to spar...@googlegroups.com, Spark View Engine Dev
Would you be interested in forking spark on github to contribute that?

Louis DeJardin

unread,
Sep 1, 2009, 12:32:50 PM9/1/09
to Spark View Engine Dev
This is now implemented for HtmlHelper<TModel> Html and
AjaxHelper<TModel> Ajax properties

On Aug 30, 10:43 pm, Louis DeJardin <louis.dejar...@gmail.com> wrote:
> Would you be interested in forking spark on github to contribute that?
>

Tim

unread,
Sep 3, 2009, 10:28:10 AM9/3/09
to Spark View Engine Dev
Thanks Louis, that's awesome. Sorry, I didn't see this message in
time, otherwise I'd have done my best to fork and add it.

Tim

Louis DeJardin

unread,
Sep 3, 2009, 11:39:43 AM9/3/09
to spar...@googlegroups.com
Not a problem - I was in the project making another change, and like
DeLight said it was pretty straightforward.

Elijah Manor

unread,
Sep 30, 2009, 3:25:38 PM9/30/09
to Spark View Engine Dev
I am trying to use the Input Builders from MvcContrib, but I am
getting the following error

d:\TFS\Web\Views\Customer\Edit.spark(25,55): error CS1061:
'System.Web.Mvc.HtmlHelper' does not contain a definition for 'Input'
and no extension method 'Input' 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 a snippet of the MvcContrib Input...

namespace MvcContrib.UI.InputBuilder.InputSpecification
{
public class Input<T> where T : class
{
private readonly HtmlHelper<T> _htmlHelper;

public Input(HtmlHelper<T> htmlHelper)
{
_htmlHelper = htmlHelper;
}

Does Spark current support using this helper?

I just started using the View Engine, so I am a newbie ;)

I am loving what I am seeing of the View Engine. Rock!

~/Elijah Manor

Adam Schroder

unread,
Oct 1, 2009, 5:25:52 AM10/1/09
to spar...@googlegroups.com
Have you added this namespace to either your _global.spark or in your config for spark.

MvcContrib.UI.InputBuilder.InputSpecification

??

Elijah Manor

unread,
Oct 1, 2009, 4:57:03 PM10/1/09
to Spark View Engine Dev
Yes

I am calling the Input like this...

<use namespace="MvcContrib.UI.InputBuilder.InputSpecification" />

!{Html.Input(c => c.Id).Partial("ReadOnly")}

I also tried...

!{Html<CustomerViewModel>.Input<CustomerViewModel>(c => c.Id).Partial
("ReadOnly")}

but it didn't work either ;)

On Oct 1, 4:25 am, Adam Schroder <adamschro...@gmail.com> wrote:
> Have you added this namespace to either your _global.spark or in your config
> for spark.
>
> MvcContrib.UI.InputBuilder.InputSpecification
>
> ??
>

Eric Hexter

unread,
Oct 1, 2009, 6:25:33 PM10/1/09
to spar...@googlegroups.com
I think the namespace of those helpers changed on the trunk of mvccontrib.
 

Eric Hexter

Principal Consultant | Headspring Systems | www.HeadspringSystems.com
email | ehe...@HeadspringSystems.com
blog | http://Hex.LosTechies.com
info | http://www.linkedin.com/in/erichexter




Matthieu GD

unread,
Oct 1, 2009, 9:44:25 PM10/1/09
to Spark View Engine Dev
I use those namespaces to get the extensions methods :

<use namespace="MvcContrib"/>
<use namespace="MvcContrib.UI"/>
<use namespace="MvcContrib.UI.Grid"/>
<use namespace="MvcContrib.UI.Pager"/>
<use namespace="MvcContrib.UI.Grid.ActionSyntax"/>
<use namespace="MvcContrib.FluentHtml"/>
<use namespace="MvcContrib.FluentHtml.Elements"/>

and I have a base page specified :

<spark>
<compilation debug="true"/>
<pages automaticEncoding="true"
pageBaseType="XXXX.SparkModelViewPage"/>
</spark>

as described here :
http://lunaverse.wordpress.com/2009/05/18/use-mvccontrib-fluenthtml-with-spark-view-engine/

On 1 oct, 18:25, Eric Hexter <eric.hex...@gmail.com> wrote:
> I think the namespace of those helpers changed on the trunk of mvccontrib.
>
> Eric Hexter
>
> Principal Consultant | Headspring Systems |www.HeadspringSystems.com
> email | ehex...@HeadspringSystems.com
> > > > > >>>>> Tim- Masquer le texte des messages précédents -
>
> - Afficher le texte des messages précédents -

Elijah Manor

unread,
Oct 5, 2009, 9:01:05 AM10/5/09
to Spark View Engine Dev
I am using that setup as well, but still get an exception when I run
the code.

I get the intellisense, but still get the error...

d:\TFS\Web\Views\Customer\Edit.spark(25,55): error CS1061:
'System.Web.Mvc.HtmlHelper' does not contain a definition for 'Input'
and no extension method 'Input' accepting a first argument of type
'System.Web.Mvc.HtmlHelper' could be found (are you missing a using
directive or an assembly reference?)

On Oct 1, 8:44 pm, Matthieu GD <m...@virtew.com> wrote:
> I use those namespaces to get the extensions methods :
>
> <use namespace="MvcContrib"/>
> <use namespace="MvcContrib.UI"/>
> <use namespace="MvcContrib.UI.Grid"/>
> <use namespace="MvcContrib.UI.Pager"/>
> <use namespace="MvcContrib.UI.Grid.ActionSyntax"/>
> <use namespace="MvcContrib.FluentHtml"/>
> <use namespace="MvcContrib.FluentHtml.Elements"/>
>
> and I have a base page specified :
>
>  <spark>
>     <compilation debug="true"/>
>     <pages automaticEncoding="true"
> pageBaseType="XXXX.SparkModelViewPage"/>
> </spark>
>
> as described here :http://lunaverse.wordpress.com/2009/05/18/use-mvccontrib-fluenthtml-w...
Reply all
Reply to author
Forward
0 new messages