This is a topic which has been rehashed over and over, I'm still not comfortable on how all the pieces fit together: ViewPage/ViewMasterPage, ViewPage.Model, so forth.
I've entered an undertaking where model data must be passed to both the MasterPage and the ViewPage that derives from it. The data that is passed down need not be shared between the MasterPage and ViewPage, in case that matters.
The solution I ended up with feels like a bit of a hack-job:
1. I abstracted the Controller and overrode the OnActionExecuted Method: The MasterViewPage accesses its data using ViewMasterPage.Model
protected override void OnActionExecuted(ActionExecutedContext filterContext) {
ViewData.Model = new CPanelViewData() { Errors = Errors, Warnings = Warnings, Notifications = Notifications };
base.OnActionExecuted(filterContext);
}
2. I use the Controller.View(string viewName, object model) in my Action Method: The ViewPage is made generic, ie ViewPage< FileManagerViewPage >
public class FileManagerControlPanelController : CPanelController
{
private FileManagerViewPage viewPage = new FileManagerViewPage();
public ActionResult AddFolder(string name, string path) {
...
...
return View("Index", viewPage);
}
All that being said, I wonder if this solution is legitimate. Is there a better way to serve Model data to the MasterPage and View?