Derived View Pages

Last post 02-02-2008 2:20 PM by Mallioch. 4 replies.

Sort Posts:

  • Derived View Pages

    02-02-2008, 1:10 PM
    • Member
      292 point Member
    • Mallioch
    • Member since 04-17-2006, 5:58 AM
    • Dallas
    • Posts 74

    Can you derive from the genericized ViewPage? I tried to do this and it isn't working for me. If I create my strongly typed view data and use ViewPage<Foo.MVCWeb.Controllers.MyCustomDataClass> as the base type for my page, all works peachy. If I make my own base page (like "Foo.UI.AdminPage<Foo.MVCWeb.Controllers.MyCustomDataClass>") and inherit from that, I get an error rendering the page when I try to use that data in a strongly-typed fashion when doing something like the following: <%= Html.ListBox("postId", ViewData.Posts, 10, false, "Title", "Id") %>. It says to me the following:

    CS1061: 'System.Web.Mvc.ViewData' does not contain a definition for 'Posts' and no extension method 'Posts' accepting a first argument of type 'System.Web.Mvc.ViewData' could be found (are you missing a using directive or an assembly reference?)

    So it is like it is expecting only the non-generic viewpage. Thoughts?

  • Re: Derived View Pages

    02-02-2008, 1:25 PM
    • Contributor
      4,372 point Contributor
    • tgmdbm
    • Member since 12-17-2007, 2:08 PM
    • Posts 883
    • ASPInsiders
      TrustedFriends-MVPs

    what does AdminPage<T> derive from?

  • Re: Derived View Pages

    02-02-2008, 1:54 PM
    • Member
      292 point Member
    • Mallioch
    • Member since 04-17-2006, 5:58 AM
    • Dallas
    • Posts 74

    The code behind for the page and its parents with all the real namespaces and names (I'm converting one of my blogs over to MVC to see how much easier/harder/different/whatever it is from normal webform development):

    public partial class ViewBlogPosts : Archaic.UI.AdminPage<Archaic.MVCWeb.Controllers.ListBlogPostsData>

    ...which inherits from...

    public class AdminPage<T> : SitePage<System.Web.Mvc.ViewData>

    ...which inherits from...

    public class SitePage<T> : System.Web.Mvc.ViewPage<System.Web.Mvc.ViewData>

    So here is a thought. I didn't make my ListBlogPostsData class inherit from ViewData. Could that be the problem? Of course, either did scottgu in part 3 of his recent series, but he's doing something different than I am...

     


     

  • Re: Derived View Pages

    02-02-2008, 2:08 PM
    Answer
    • Contributor
      4,372 point Contributor
    • tgmdbm
    • Member since 12-17-2007, 2:08 PM
    • Posts 883
    • ASPInsiders
      TrustedFriends-MVPs

    class AdminPage<T> : SitePage<T>

    class SitePage<T> : ViewPage<T>


  • Re: Derived View Pages

    02-02-2008, 2:20 PM
    • Member
      292 point Member
    • Mallioch
    • Member since 04-17-2006, 5:58 AM
    • Dallas
    • Posts 74

    Well...don't I feel like an idiot :)

    Thanks! 

Page 1 of 1 (5 items)