Alias ViewData.Model

0 views
Skip to first unread message

Mat

unread,
Feb 8, 2010, 6:02:18 AM2/8/10
to Spark View Engine Dev
Is there an easy way to define a global alias for ViewData.Model e.g.
m or heck I'd settle for model e.g. the way its aliased in the
viewdata tag.

so I can use ${m.Name} rather than ${ViewData.Model.Name}

Perhaps this is not the standard way of working with Spark, a few
experiments I know I can have alias that reference a key in the
viewdata dictionary but not directly the strong type Model, Im porting
an app which has one strong type view model per view and want to
continue this route as easily/char-less as possible

Curtis Mitchell

unread,
Feb 8, 2010, 7:05:57 AM2/8/10
to spar...@googlegroups.com
try <var m="ViewData.Model as [type]" /> in your view page. That should give you 'm' as a strong-typed representation of your Model.
Sent from my mobile
--
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.

Sean Chambers

unread,
Feb 8, 2010, 8:33:33 AM2/8/10
to spar...@googlegroups.com, spar...@googlegroups.com
I did something similar except I derived from the base view class and
created my own custom view class so I didn't need to continually cast
my viewmodel in the views.

Sean

On Feb 8, 2010, at 7:05 AM, "Curtis Mitchell"

Tom Janssens

unread,
Feb 8, 2010, 10:23:16 AM2/8/10
to Spark View Engine Dev
Add the following line in Application.spark :
# var m = Model;

that's it

Louis DeJardin

unread,
Feb 8, 2010, 2:52:49 PM2/8/10
to spar...@googlegroups.com
try also <viewdata model="MyType foo"/> to see if that creates a foo accessor for the Model property

Reply all
Reply to author
Forward
0 new messages