Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC passing strongly typed data to master page

Tags:

asp.net-mvc

Duplicate

Passing data to Master Page in ASP.NET MVC

Should an ASP.NET masterpage get its data from the view ?

I have been following this method for passing common data to the site.master. However, this does require specific casting of the ViewData and I don't like using string identifiers everywhere. Is this the best way to do it or is there another way?

http://www.asp.net/learn/MVC/tutorial-13-cs.aspx

Thanks

like image 348
Jon Archway Avatar asked Apr 02 '09 16:04

Jon Archway


1 Answers

You could create a base class that all your models inherit from:

class MasterModel {
     // common info, used in master page.
}

class Page1Model : MasterModel {
     // page 1 model
}

Then your master page would inherit from ViewMasterPage<MasterModel> and your Page1.aspx would inherit from ViewPage<Page1Model> and set Site.master as its master page.

like image 163
mmx Avatar answered Sep 20 '22 00:09

mmx