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

  • SEARCH
  • Home
  • 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 6789409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:36:02+00:00 2026-05-26T17:36:02+00:00

AFAIK, there are two ways of passing data to the view from controller :

  • 0

AFAIK, there are two ways of passing data to the view from controller : one being loosely typed(using ViewBag or ViewData), other being strongly-typed. Most recommend the latter because of strong compile-time checking.

In a dynamic web application, we come across scenarios when there is a requirement to pass multiple entities from the controller to the view. In that case, one can either pass a single entity as a model and rest in ViewBag dictionary. Or One can make an entirely new ViewModel class merging the various entities and then passing it to the view.

Recently, I encountered such an issue; I needed to pass a category model which had list of subcategories and products registered with it as properties. And then in the view, I needed to diplay the subcategories along with making sure that pagination occurs on products collection if they are more than 10. Therefore i couldn’t use a strongly typed view for either Category Model or Product Model.

The Solution was presented by follow peers, tvanfosson and Ufuk Hacıoğulları(Many thanks to both) in this Post. And that is to use a ViewModel. I am still trying to understand and work on it and it seems to be the proper solution.

Question : Is this a better way to handle such situations ? Also, when is it recommended to use ViewModel and when to bypass it in favour ViewBag & a Model.

  • 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-26T17:36:03+00:00Added an answer on May 26, 2026 at 5:36 pm

    The one and only purpose of a Viewmodel class is to contain (strongly typed) data to be sent to a view by an action method.

    So as the answers in your referred question suggest create a Viewmodel class which contains properties for all the data you need in your view.

    The advantage of Viewbag usage is that you don’t have the overhead to create a separate class.
    The disadvantage is that you don’t have compile time type checking and intellisense available.

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

Sidebar

Related Questions

AFAIK there is only a vulnerability within the HEADERS of an email when using
This is a best practices type of question. AFAIK there are two approaches (and
AFAIK you can load one DataSet from another DataSet via IDataReader i.e. new DataSet().Load(existingDataSet.CreateDataReader());
AFAIK one of the objectives of Stack Overflow is to make sure anyone can
How do I accumulate values in T-SQL? AFAIK there is no ARRAY type. I
In my application the main thread creates two joined threads; one which waits for
Using SQL Server 2K8 R2, I have two related tables - Member and Questionnaire.
Is there any way for me to share a variable between two web workers?
Possible Duplicate: Is there any particular difference between intval and (int)? These two statements
AFAIK, Currency type in Delphi Win32 depends on the processor floating point precision. Because

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.