HtmlHelper<T>

26 views
Skip to first unread message

Chris

unread,
Nov 27, 2009, 8:36:15 AM11/27/09
to Spark View Engine Dev
Is there any way of getting an HtmlHelper<T> instance in a spark
view? I'm trying to use some third part extensions that depend on
it. I did find this post (
http://groups.google.com/group/spark-dev/browse_thread/thread/618bd44a94368d22/d6fa365fb2d7392f?show_docid=d6fa365fb2d7392f
) and so downloaded the latest build from the TeamCity install on
codebetter.com but I still can;t seem to find the the strongly typed
helper. Any ideas? If this hasn't actually been done I'm quite happy
to fork on gh and give it a go myself.

Artem Tikhomirov

unread,
Dec 6, 2009, 7:42:58 PM12/6/09
to spar...@googlegroups.com
You should create your personal base class for Spark views. Then you should create it's generic derivative having new Html property returning  strongly typed HtmlHelper<T>.


--

You received this message because you are subscribed to the Google Groups "Spark View Engine Dev" group.
To post to this group, send email to spar...@googlegroups.com.
To unsubscribe from this group, send email to spark-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spark-dev?hl=en.



Louis DeJardin

unread,
Dec 7, 2009, 2:12:02 PM12/7/09
to spar...@googlegroups.com
I'm kind of curious also - does <use model="YourModelClass"/> make a difference in that case?

Erik van Brakel

unread,
Jan 3, 2010, 4:16:10 PM1/3/10
to Spark View Engine Dev
This is the exact same problem I'm having right now. AFAIK, the
DisplayFor<T> Html helper in MVC2 depends on the generic
HtmlHelper<..>. So far I didn't manage to get this to work in spark.
I'm too new to spark to actually say something technically meaningful
about this, but it would be nice if <use model="SomeModel" /> would
trigger the generic Html helper instance.

On Dec 7 2009, 8:12 pm, Louis DeJardin <louis.dejar...@gmail.com>
wrote:


> I'm kind of curious also - does <use model="YourModelClass"/> make a
> difference in that case?
>
> On Sun, Dec 6, 2009 at 4:42 PM, Artem Tikhomirov <ar...@tikhomirovs.ru>wrote:
>
> > You should create your personal base class for Spark views. Then you should
> > create it's generic derivative having new Html property returning  strongly
> > typed HtmlHelper<T>.
>

> > On Fri, Nov 27, 2009 at 4:36 PM, Chris <cmdrk...@googlemail.com> wrote:
>
> >> Is there any way of getting an HtmlHelper<T> instance in a spark
> >> view?  I'm trying to use some third part extensions that depend on
> >> it.  I did find this post (
>

> >>http://groups.google.com/group/spark-dev/browse_thread/thread/618bd44...


> >> ) and so downloaded the latest build from the TeamCity install on
> >> codebetter.com but I still can;t seem to find the the strongly typed
> >> helper.  Any ideas? If this hasn't actually been done I'm quite happy
> >> to fork on gh and give it a go myself.
>
> >> --
>
> >> You received this message because you are subscribed to the Google Groups
> >> "Spark View Engine Dev" group.
> >> To post to this group, send email to spar...@googlegroups.com.
> >> To unsubscribe from this group, send email to

> >> spark-dev+...@googlegroups.com<spark-dev%2Bunsu...@googlegroups.com>


> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/spark-dev?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Spark View Engine Dev" group.
> > To post to this group, send email to spar...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > spark-dev+...@googlegroups.com<spark-dev%2Bunsu...@googlegroups.com>

Thomas G. Mayfield

unread,
Jan 19, 2010, 2:03:15 PM1/19/10
to Spark View Engine Dev
I'm using the 1.0 release, and since there's no easy way to override
the creation of SparkView.Html, this is how I got around it:

public abstract class MySparkView
: SparkView
{
}

public abstract class MySparkView<TModel>
: SparkView<TModel>
where TModel : class
{
public new HtmlHelper<TModel> Html
{
get
{
HtmlHelper<TModel> result = base.Html as HtmlHelper<TModel>;
if (result == null && base.Html != null)
{
result = new HtmlHelper<TModel>(base.Html.ViewContext,
base.Html.ViewDataContainer);
base.Html = result;
}
return result;
}
}
}

Then using the SparkSettings object (I use code to build it up instead
of Web.config):

mySettings.SetPageBaseType(typeof(MySparkView))

I haven't fully tested the change (I'm in the middle of a project
rewrite when I discovered that my converted .aspx views couldn't use
typed helpers anymore), but that portion, at least, is passing view
compilation.

> > >> spark-dev+...@googlegroups.com<spark-dev%2Bunsubscribe@googlegroups .com>


> > >> .
> > >> For more options, visit this group at
> > >>http://groups.google.com/group/spark-dev?hl=en.
>
> > >  --
> > > You received this message because you are subscribed to the Google Groups
> > > "Spark View Engine Dev" group.
> > > To post to this group, send email to spar...@googlegroups.com.
> > > To unsubscribe from this group, send email to

> > > spark-dev+...@googlegroups.com<spark-dev%2Bunsubscribe@googlegroups .com>

Reply all
Reply to author
Forward
0 new messages