Please can anybody point out where this code might be going wrong. I am trying to create a partial class for the masterpage.
The master pages class:
namespace MuniWeb.Models.SiteMaster{ public class BaseViewData { public string Title { get; set; } public string MetaKeywords { get; set; } public string MetaDescription { get; set; } } public partial class Site : System.Web.Mvc.ViewMasterPage<MuniWeb.Models.SiteMaster.BaseViewData> { public Site() { ViewData.Model = new BaseViewData(); } }}
The master page:
<%@ Master Language='C#' Inherits='System.Web.Mvc.ViewMasterPage<MuniWeb.Models.SiteMaster.BaseViewData>' %>
The error:
Object reference not set to an instance of an object. Line 33: <div id='footer'> Line 34: ApplicationID: Line 35: <%= Model.Title %> Line 36: </div> Line 37: </div>
I am just using this as an example. The code I want to use needs to fire for every page to check certain parameters, this is why it is in the master page.
You shouldn’t need to make a partial class. What does your controllers action code look like? The error looks like it could be from not handing the View (and therefore it’s master page) a model.
Try something like this:
Then define your master page like you had:
Now in your controller
See how that goes…
I would ask why the MasterPage NEEDS strongly type ViewData. I understand that yes, sometimes strongly typed viewdata is needed in masterpages but generally you should be able to get way with just using the ViewData name value collection.