views:

403

answers:

7

Hi,

Trying to create a view page in my asp.net-mvc app.

I have a strongly typed view, and I have also ovverriden the MVCPage class also.

For some reason when I load the page it says it can't load the type:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
Line 2:  Inherits="Blah.MyViewPage<Blah.ViewDataForBLahPage>" %>



public class MyViewPage<TViewData> : ViewPage<TViewData> where TViewData : class 


public class ViewDataForBlahPage : MyViewData
A: 

The code you posted is quite confusing to me so I'm not sure what's wrong. But this is how I make mine to work (i.e. page without code-behind):

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MyCustomViewModel>" %>

Replace MyCustomViewModel with your own view model class since you mentioned your view is a strongly-type view.

If it still doesn't work, might be posting more detailed code & reported error may make it easier for people to help...

Buu Nguyen
A: 

You need to inherit

System.Web.Mvc.ViewPage<Blah.ViewDataForBLahPage>
Malcolm Frexner
If you follow his class hierarchy, he is doing just that.
mxmissile
Oh I guess you are right. The Blah got me confused.
Malcolm Frexner
A: 

I have had this happen to me before, if I recall it happened when upgrading a site from a beta version of MVC. The fix for me was to create a new MVC project and add re-add everything to it.

mxmissile
A: 

Where is the namespace declaration for the class?

ETA: have you seen this thread? Could it be the same error?

Nikki9696
A: 

Check your web.config file, particularly the <pages/> section. You may need to add the MYBlah.Core namespace to the namespace list.

Stuart Branham
A: 

Maybe it's because your class is non-generic, but you reference it as a generic class here:

 Inherits="MYBlah.Core.MyViewPage<MyBlah.Core.ViewDataForUser>"

For .NET, a generic class MyViewPage is different than MyViewPage<T>.

chris166
I updated my post, but I have a generic overload. thanks!
mrblah
In that case... since the type couldn't be loaded, there might be a TypeLoadException involved. You could attach a debugger, set it to break at all exceptions and look at the details
chris166
A: 

check this answer : http://stackoverflow.com/questions/615044/mvc-no-codebehind-strongly-typed-viewdata-headers-not-working hope it will help you!