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 6473499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:28:25+00:00 2026-05-25T06:28:25+00:00

Let’s say I have a theoretical MVC framework that uses a ViewData object to

  • 0

Let’s say I have a theoretical MVC framework that uses a ViewData object to pass data from the controller to the view. In my controller, let’s say I have some code like this (in pseudocode):

function GetClientInfo()
{
    // grab a bunch of data from the database
    var client = Database.GetClient();
    var clientOrders = Database.GetClientOrders();
    var clientWishList = Database.GetClientWishList();

    // set a bunch of variables in the ViewData object
    ViewData.set("client", client);
    ViewData.set("clientOrders", clientOrders);
    ViewData.set("clientWishList", clientWishList);

    showView("ClientHomePage");
}

And then in my ClientHomePage view, I display the data like so:

<p>Welcome back, [ViewData.get("client").FirstName]!</p>

<p>Your order history:</p>
<ul>
    [Html.ToList(ViewData.get("clientOrders")]
</ul>

<p>Your wishlist:</p>
<ul>
    [Html.ToList(ViewData.get("clientWishList")]
</ul>

This is what I understand MVC to be like (please correct me if I’m wrong). The issue I’m having here is those magic strings in the view. How does the view know what objects it can pull out of the ViewData object unless it has knowledge of what the controller is putting in there in the first place? What if someone does a refactor on one of the magic strings in the controller, but forgets to change it in the view, and gets a runtime bug instead of a compile-time error? This seems like a pretty big violation of separation of concerns to me.

This is where I’m thinking that a ViewModel might come in handy:

class ClientInfo
{
    Client client;
    List clientOrders;
    List clientWishList;
}

Then the controller creates an instance of ClientInfo and passes it to the view. The ViewModel becomes the binding contract between the controller and the view, and the view does not need to know what the controller is doing, as long as it assumes that the controller is populating the ViewModel properly. At first, I thought this was MVVM, but reading more about it, it seems like what I have in mind is more MVC-VM, since in MVVM, the controller does not exist.

My question is, what am I not understanding here about MVC vs. MVVM? Is referring to variables in the ViewData by magic strings really not that bad of an idea? And how does one insure that changes made in the controller won’t adversely affect the view?

  • 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-25T06:28:25+00:00Added an answer on May 25, 2026 at 6:28 am

    Your understanding of MVC is wrong, it stands for Model View Controller but you are missing the Model in your example. This is the typed entity that gets passed back to the View to do the rendering. In ASP.Net MVC you would use typed Views that also type the Model within the View so it is checked at compile time. This eliminates the need for magic strings (second part of your question).

    In MVVM you have Model View ViewModel. This is a way of binding a ViewModel directly to the UI layer via a View which is used a lot in WPF. It replaces the need for a controller and it’s generally a 1-to-1 mapping with the UI. It’s just an alternative mechanism that solves the same problem (of abstraction and seperation of concerns) but better suited to the technology.

    Theres some useful info here which might help understand the difference.

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

Sidebar

Related Questions

Let's say I'm building a data access layer for an application. Typically I have
Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,
Let's say i have an android device that has some extra buttons on it,
Let's say I have a javascript array with a bunch of elements (anywhere from
Let's say I have a Border whose DataContext is an object of type MyViewModel.
Let's say I have a JS in one file that creates a Viewport :
Let’s say I have a data grid and there’s a method attached to clicking
Let's say, for the sake of argument, that I have 30 asp.net web applications
Let's say I have an int that represents the number of rows in a
Let's say I have a UITableView that is part of an iPad app doesn't

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.