Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 976309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:43:38+00:00 2026-05-16T03:43:38+00:00

There seem to be multiple means of passing model data from controllers in asp.net

  • 0

There seem to be multiple means of passing model data from controllers in asp.net mvc to views. Its not clear to me if there’s a recommended approach in the mvc v1 and v2 releases or if like most things in life, it depends. I’ve seen several approaches:

Option 1 – Populate the controller’s ViewData dixtionary in either an icky string-based indexing way with casting in the view, or the in a strongly typed way by creating a strongly typed custom model class and passing that via ViewData.

Option 2 – Use ViewData.Model, which I’m not sure I even understand.

Option 3 – Use ViewPage.Model, in which case I’m not sure how you pass the model data from the controller.

I’ve seen a number of posts poo-pooing options 1 and 2 but I don’t understand why. These posts seem to highly recommend 3 in most cases.

How do you approach this? Is there a standard way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:43:39+00:00Added an answer on May 16, 2026 at 3:43 am

    Every view ‘should’ have a specific model. This is sometimes more work so people use short cuts like ViewData, which works but is just not as clean and type safe in my opinion, so I prefer to have everything in the view’s model.

    You can then make all your views stongly typed. This is a very clean way to do so. Then in your controller you just call the view like:

    YourViewModel model = new YourViewModel()
    {
        // initialize the data here
    };
    View(model);
    

    Then in your views you can access all the data via ViewPage Model and it is all type safe and enforced from the controller as well.

    EDIT from comments:

    You don’t need to use ViewData at all if you don’t want. You can encapsulate all the data your view needs in a model. Just like the example you quoted with ProductsListViewData. It’s just a model that contains all the items that were going to be stored in the ViewData. Both ways work but when you encapsulate it in a class (preferred method where everything is in the model) then all the bits and pieces are strongly typed.

    ViewData is a generic container so even though you can just put anything you want into it, it is not type safe and therefore not as ‘clean’. It comes down to preference and maintainability. There is only option 1 and 3. Your option 2 is misunderstood and is just option 3 in reality. There is no ViewData.Model just ViewPage.Model.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It would seem that there is a much simpler way to state the problem.
For a current MVC3 project I have a model that has multiple pages for
The main question here is: is there a standard method of writing UNIX shell
I use TeamCity which in turn invokes msbuild (.NET 4). I have a strange
I was wondering if there was a way to calculate the rpm of a
So say I have a Question model and an Answer model and Question has_many
I am creating a silverlight card game which talks to a WCF service using
I know what a static array is and how to use it in Java,
I recently began importing a number of our projects into a Subversion repository at
I'm really confused - but really it's pretty wierd because I know two programming

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.