Results 1 to 4 of 4

Thread: How to use model for multiple lists of data

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2015
    Posts
    83

    How to use model for multiple lists of data

    What's the best way to pass multiple lists of data to a view? I saw someone answer the question on another site and they said to use the model for one list and ViewData for the other. That seems pretty weak to me. From what I understand the model is the preferred method for passing data to a view. I'm assuming the model would be able to handle more than one list.

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: How to use model for multiple lists of data

    If you create a custom model for the view (often referred to as a ViewModel) you could give the model two properties, each property would contain the data for the associated list.

    Personally I would always try to avoid using ViewData (or ViewBag) as you lose all type safety and compile time support, a strongly typed model is always the way to go in my mind.

  3. #3
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: How to use model for multiple lists of data

    Personally I would always try to avoid using ViewData (or ViewBag) as you lose all type safety and compile time support, a strongly typed model is always the way to go in my mind.
    Agreed, i have models with multiple lists in which i bind to dropdowns or grids, its fairly standard.
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  4. #4
    Banned
    Join Date
    Dec 2019
    Posts
    9

    Re: How to use model for multiple lists of data

    Quote Originally Posted by PlausiblyDamp View Post
    If you create a custom model for the view (often referred to as a ViewModel) you could give the model two properties, each property would contain the data for the associated list.

    Personally I would always try to avoid using ViewData (or ViewBag) as you lose all type safety and compile time support, a strongly typed model is always the way to go in my mind.
    Totally agree with you here!

Posting Permissions

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



Click Here to Expand Forum to Full Width