strongly type viewmodel isn't rendering?

6 views
Skip to first unread message

Sean Chambers

unread,
Nov 19, 2009, 11:06:17 PM11/19/09
to Spark View Engine Dev
I am trying to get my view model to render the properties on the spark
template like so:

<viewdata Message="string" Model="CompanyDto" />

and then reference them on the page using:

${Model.Companyname}
${Model.ContactName}

and so on. Spark won't render these items and just prints them on the
output. I also tried setting Model to lowercase like so:

<viewdata Message="string" model="CompanyDto" />

but then it seems as if spark thinks I'm referencing a namespace when
doing ${Model.CompanyName}:

_CompanyForm.spark(8,102): error CS0234: The type or namespace name
'CompanyName' does not exist in the namespace
'Product.ClientModels.Model' (are you missing an assembly reference?)

My settings look like so:

var settings = new SparkSettings();
settings.SetPageBaseType( typeof
(Controllers.MyProductView) );
settings.AddNamespace( "Product.ClientModels.Dto" );
settings.AddNamespace( "Product.Controllers" );
settings.SetDebug(true);
settings.AddNamespace( "System.Collections.Generic" );
settings.AddNamespace( "System.Web.Security" );
settings.AddNamespace( "System.Web" );

Whats the proper way to render a strongly type ViewData.Model items on
the spark page without it blowing up?

Sean Chambers

unread,
Nov 19, 2009, 11:08:59 PM11/19/09
to Spark View Engine Dev
I should also add this started happening after I created my own view
base types like so:

public abstract class FlightDeckView : SparkView
{
}

public abstract class FlightDeckView<TModel> : FlightDeckView
{
public SecurityHelper Security { get { return new SecurityHelper
(); } }

Sean Chambers

unread,
Nov 19, 2009, 11:18:21 PM11/19/09
to Spark View Engine Dev
I fixed the namespace error. that was my own stupidity.

The problem now is I'm not sure how to properly reference the viewdata
model on the page. When i do ${Model.Whatever}, it just prints that
into the input fields as if there is nothing in the viewdata by that
name

Josh Flanagan

unread,
Nov 20, 2009, 8:36:11 AM11/20/09
to spar...@googlegroups.com
Not sure if this is a copy/paste error, but your settings show you
using MyProductView as your page base type, but then in the next post
you show FlightDeckView as your page base type. Those definitely need
to match up.
Also, FlightDeckView<TModel> should probably derive from SparkView<T>,
instead of FlightDeckView (which derives from the non-strongly-typed
SparkView)
> --
>
> 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=.
>
>
>

Sean Chambers

unread,
Nov 22, 2009, 7:08:33 AM11/22/09
to spar...@googlegroups.com
Thanks Josh. That wa just a typo int post. They are both the same. I
have since figured out that I needed to provide a model property on
the strongly typed page base and that got it working. Thanks

Sean



On Nov 20, 2009, at 8:36 AM, Josh Flanagan <joshuaf...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages