views:

41

answers:

1

I'm setting up a wizard. All of my wizard views need access to common data for display like TotalWizardSteps and CurrentWizardStep. I'm trying to find the best way to go about adding this common data to the ViewDataDictionary. I'm thinking of creating my own WizardStepViewPage. This subclass would have a property 'WizardData' which returns a WizardData object. This would allow me to write the following code in my views:

<p>Wizard Step:<%= WizardData.CurrentStep %></p>

The backing store for this WizardData object would be the ViewDataDictionary and some unlikley to reproduce key like "__TheWizardData". I'd set the value at this key with an actionfilter.

This sounds messy, but I think it will work. Is it dumb though? Is there a better way to achieve this?

I want:

  • Strongly typed access to wizardData in html markup
  • To make my actions ignorant of the need to construct wizardData
  • To make my strongly typed viewData classes ignorant of wizardData
+2  A: 

I think you should create a model class that holds the necessary info and use it to create a strongly typed view.

I don't see a good reason you might want to hide the WizardData from strongly typed models but if you really want to do so, why don't you create an extension method for ViewPage instead of inheriting? Inheritance wouldn't work well for different types of ViewPage (typed, untyped).

Mehrdad Afshari
Note the last bullet.
TheDeeno
If you need this WizardData thing in *every* page, I don't see any reasons you might want to hide it.
Mehrdad Afshari
If I can keep the viewData ignorant of wizardData then I can create a WizardControllerBase and reuse this wizard functionality with any viewdata without having to remember how or the need to build wizard data.
TheDeeno
I could be mistaken though. I guess I could make a WizardStepResult that requires an IWizardData, but it'd be nice to not have the requirement for wizardData be spread out across all the actions. I'd like the base controller to handle this for me.
TheDeeno
nice, an extension might work.
TheDeeno
actually an extension won't work. WizardData will only be available to certain pages not all. Thanks for the help though.
TheDeeno
and that's exactly why I'm not with the idea of *hiding* it.
Mehrdad Afshari