SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)

    Question Getting a little lost in the modeling...

    I need some advice on my models. Here's the situation...

    I have a namespace with my raw record-level models in it. Examples would be:
    Models.Data.CategoryModel
    Models.Data.ForumModel

    Note: CategoryModel has a read only propery called Forums of type List(of ForumModel) and so one for other models in this namespace.

    Now, if it were a simple matter of passing these around, things would be a snap, but I've run across instances where the above don't have enough data for a collection form or display form.

    For example. The site index displays a category forum listed (which could be done by filling out and setting ViewData.Model to a CategoryModel. But! We also need additional information, such as an online use list and some stats.

    I could stuff this extra data into the base collection (ViewData("users") = ...) but I don't like that approach.

    I toyed with the idea of making another namespace such as Models.Meta where I can extend things and provide models such as HomeIndexModel, which would have properties for the CateogryModels, OnlineUsers, and Stats. So I could use them in the views.

    Now the problem becomes in binding. While I can bind something like RegisterUserModel using RegisterUserBinder, but the resulting object isn't explicitly the same as a UserModel. It may contain only partial information, or perhaps even additional things.

    What is the best approach for managing these types of discrepencies?

    In addition, in some admin index views, I need to be able to display the list of items, where one column contains a textbox with the "sequence" field in it. I need to be able to edit these, right here on the this page, and click "Update Order" to save them back. The problem is, this involves a more complex html element naming convention than what I think mvc htmlhelper provides.

    Again, what is the best way around the above?

    Thanks!

  2. #2
    Non-Member
    Join Date
    Oct 2007
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It might be helpful to list the framework you're using. You'll get a reply quicker.

  3. #3
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    lol whoops. I'm used to a few people in particular who already know me. I'm using the ASP.NET MVC framework. Sorry about my assumption.

  4. #4
    Non-Member
    Join Date
    Oct 2007
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh. You're ok. I didn't realize the thread was in the .net forum cause I found it in search. My bad.

  5. #5
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    I just make rather local classes to wrap the data up then send that down the pipeline in the strongly typed view data. I also use a wrapper class for ther presentation data that contains references to the various other bits one needs in complex views.

  6. #6
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wwb_99 View Post
    I just make rather local classes to wrap the data up then send that down the pipeline in the strongly typed view data. I also use a wrapper class for ther presentation data that contains references to the various other bits one needs in complex views.
    Usually, you're responses are a little more spot on. What I'm wanting to know is whether or not I'm over engineering things and why or why not.

    Let demonstrate in psuedo-code real quick...

    Models.Data.BookModel
    - Name as string
    - Chapters as List(of ChapterModel)

    Models.Data.ChapterModel
    - Name as string
    - Book as BookModel

    (The above would of course be used in BookController and ChapterController and other places where single records need to be passed)

    Models.Meta.BookListModel (for use in sending grouped items into a view for display, such as an in HomeIndex)
    - BooksRead as List(of BookModel)
    - BooksOwned as List(of BookModel)
    - BooksWanted as List(of BookModel)

    Is this scenario reasonable or should I stick with using a single type of item or list(of item) for ViewData.model?

  7. #7
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We use view models for sending down data to the view and we have a specific view for each view model, based on the model type; a UserCreateModelView.aspx for UserCreateModel. We removed the reponsibility of the the view selection from the controller. We've found this really helps simplify view logic and means less C# code is required and not a single if or foreach. This also applies to partials, and we use differing masterpages to reuse the same .aspx page as a page and as a partial. Our view model only contains data for that view, and use a similar presentation wrapper like Wyatt mentioned.

    A snapshot of our project structure looks like this:

    Project.Domain.Model
    - User
    Project.Web.PresentationModels
    - IPresentationModel<T>
    - PresentationModel<T>
    - UserAdministrationPresentationModel
    Project.Web.ViewModels
    - UserCreateModel
    - UserCreatedModel
    - UserLogOnModel
    Project.Web.UI
    - UserCreateModelView.aspx
    - UserCreatedModelView.aspx
    - UserLogOnModelView.aspx

    Using the convention, while we do end up with classes, they ae generally lightweight and easy to maintain.

  8. #8
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Ok, thanks. That's very similar to what I was thinking of doing. Using a strongly typed View and a custom viewData class. So now I have the following (this is a fairly small app):

    Models.Data.SampleDataModel
    Models.View.SampleViewModel

    Binders.Data.SampleDataBinder (just in case I need them)
    Binders.View.SampleViewBinder (will mostly be using these)

    ViewModels pass between View and Controller, the DataModels pass between controllers, processors (my logic units), validators, and providers (the db interfaces).

    An action might pass the model on like this:

    dim viewModel as SampleViewModel = new SampleViewModel
    ' set props and stuff
    return View(viewName, viewMaster, viewModel)

    Then have a ViewPage(of SampleViewModel) so I can access the properties in the view aspx.

    Does that sound reasonable?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •