Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Viewdata and masterpage

Status
Not open for further replies.

whosrdaddy

Vendor
Mar 11, 2003
4,231
BE
I have this problem:

I have an MVC site with spark viewengine and I want to achieve this:

masterpage (Application.spark) must show the name of the logged in user.
content pages will show other data.

As I understand it, I can't have different models for viewdata. So masterpage uses viewdata of type UserDTO and for example my index() view uses viewdata of type UserListViewModel.

the way I'm solving it at the moment is using spark content blocks and pass in the user data in each viewmodel.
So my UserListViewModel has a property currentUser which is in turn a UserDTO. This means I have to fill in this content block for EACH view and pass in the data (aka Model.currentUser.Fullname).
And each viewmodel needs to have a currentUser property.

Is there another way to achieve this, or am I missing something?

Cheers,
Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
With MonoRail there is the concept of ViewComponents. I believe with MS MVC 2.0 the concept is called Areas. VC/Areas act as a mini controller and are part of the same request.

the flow works like this
1. user makes request
2. asp.net selects the proper controller
3. controller gets data and returns a view
4. view begins rendering
5. view encounters an Area/VC
6. controller for the Area/VC is resolved
7. Area/VC gets data and renders its view
8. the controller's view continues rendering

so in you're scenario you would have an Area on the master page. Logic within the Area Controller would resolve the user's full name and place this in the area's view model.

I believe there is information in the Spark documentation about the Area syntax. also has information about how to separate view model data with Areas.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
So this means I need to go with MVC2 RC (is it out yet?)? (using 1 at the moment). I need to create a modular website,ie adding a DLL in the bin directory, should add content to the main page.

mmm, lots of things to learn (again, was getting up to speed with MVC 1 and spark).

Thanks Jason, will check it out!

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Finally went with the "Blocks" implementation from the Spark ViewEngine modular sample.

/daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top