0
votes

In my site I have the same MasterPage for both MVC Views and WebForm Pages.

I want to use ViewData inside the MasterPage code behind.

I'm getting an exception:

A ViewMasterPage can be used only with content pages that derive from ViewPage or ViewPage.

public partial class MasterPage : System.Web.Mvc.ViewMasterPage

{

protected void Page_Load(object sender, EventArgs e)
{
    ViewData["X"] = "data";
  • This Code worked in a WebSite project - but I just converted to Web Application and I can't get it work run.

  • The Content Page inherits System.Web.Mvc.ViewPage

  • The ViewData need to be the same object in the pages and masterPages code behind.

Thanks

Rafael.

1

1 Answers

0
votes

It may not be ideal for your purpose but one property bag that does exist and is easily accessible when running through MVC or WebForms views or code behind is the HttpContext.Items dictionary.