tags:

views:

25

answers:

1

Have a problem with master page views and models.

In the first image, I have a simple view in which I am trying to access the Model properties. None of the model properties are available at this time (this is the problem).

If I use a <%= Model.blah %> then you can see that the model properties are available. Second photo.

In the last photo you will now see that I can access the Model properties that I was trying to access in the first photo.

An error will be thrown if viewing this page if you don't first do <%= with the model. CS1061: 'object' does not contain a definition for 'User' and no extension method 'User' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

http://yfrog.com/8b43656447p

So why is this happening?

A: 

Your view inherits System.Web.Mvc.ViewMasterPage<AuthModel> which of course is wrong as it is an aspx page. Make it inherit from System.Web.Mvc.ViewPage<AuthModel> and it should work:

<%@ Page 
    Language="C#" 
    MasterPageFile="~/Views/Shared/Base.Master" 
    Inherits="System.Web.Mvc.ViewPage<AuthModel>" 
%>
Darin Dimitrov
Using nested master pages.
James