3

I'm trying to create a view page in my asp.net-mvc app. For this, 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
Claus Jørgensen
  • 25,882
  • 9
  • 87
  • 150
mrblah
  • 99,669
  • 140
  • 310
  • 420
  • possible duplicate of [mvc no codebehind strongly typed viewdata headers not working](http://stackoverflow.com/questions/615044/mvc-no-codebehind-strongly-typed-viewdata-headers-not-working) – David Basarab Sep 22 '11 at 15:16

6 Answers6

0

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
  • 49,745
  • 5
  • 67
  • 85
0

You need to inherit

System.Web.Mvc.ViewPage<Blah.ViewDataForBLahPage>
Mathias F
  • 15,906
  • 22
  • 89
  • 159
0

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
  • 11,464
  • 3
  • 53
  • 79
0

Where is the namespace declaration for the class?

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

Community
  • 1
  • 1
Nikki9696
  • 6,260
  • 1
  • 28
  • 23
0

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

Samantha Branham
  • 7,350
  • 2
  • 32
  • 44
0

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
  • 4,769
  • 4
  • 24
  • 25
  • 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 Jul 01 '09 at 21:02