Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 17, 2008 11:19 AM by James Crowley
Apr 19, 2008 01:55 PM|LINK
There was something I thought was a bug in the previous releases - that remains in the current release - so I wanted to check you new about it - or maybe there's a nicer solution. Basically the issue is if the site's MasterPage has a type of ViewMasterPage<BaseViewData>
and you're views are type ViewPage<SomePageViewData> (where SomePageViewData inherits from BaseViewData), you get a "A ViewMasterPage<TViewData> can only be used with content pages that derive from ViewPage<TViewData>." error. I get why this is happening
- but does it not make sense to put up with a possible cast to allow for scenarios like this.
I'd be using the following to work around this:
public class MasterPageBugFix<TViewData> : System.Web.Mvc.ViewMasterPage<TViewData>
public new TViewData ViewData
TViewData d = (TViewData)this.ViewContext.ViewData;
if (null == d)
throw new InvalidOperationException();
and then make my MasterPage inherit from that. The only other solution I've seen is to force all the pages to inherit from the same base view data and do the casting there - which feels nasty. What do you think? Any more elegant solutions?
May 17, 2008 11:19 AM|LINK
(sorry - scraop that - all ok now)