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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:28:01+00:00 2026-05-27T16:28:01+00:00

Just wondering what the actual difference between the ViewData that is bound to the

  • 0

Just wondering what the actual difference between the ViewData that is bound to the MVC view and the ViewData that is bound to the @Html helper object?

I have written a page and they don’t seem to refer to the same thing. Is ViewData used anywhere else in the application as another dictionary hidden under the same name?

  • 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-27T16:28:02+00:00Added an answer on May 27, 2026 at 4:28 pm

    SHORT ANSWER:
    The HtmlHelper‘s ViewData is based on the view’s data. So it has same values upon entering view code (for example, Razor or ASPX page). But you can change these ViewDatas separately.

    It is used same way in AjaxHelper.

    RepeaterItem has it’s own ViewData, which is based on the item.

    I have not found any use of different ViewData anywhere.

    UPDATE:
    ViewData and @Html.ViewData are different only when you use a strongly typed view. If you use a not strongly typed view, both they are equal as reference. So I think this was done to wrap the ViewData into strongly typed ViewDataDictionary<>.


    SOME INVESTIGATIONS:

    I have taken a look at the decompiled sources and here is what I found.

    Let’s see, what is @Html.ViewData:

    namespace System.Web.Mvc
    {
      public class HtmlHelper<TModel> : HtmlHelper
      {
        private ViewDataDictionary<TModel> _viewData;
    
        public ViewDataDictionary<TModel> ViewData
        {
          get
          {
            return this._viewData;
          }
        }
    
        public HtmlHelper(ViewContext viewContext, IViewDataContainer viewDataContainer)
          : this(viewContext, viewDataContainer, RouteTable.Routes)
        {
        }
    
        public HtmlHelper(ViewContext viewContext, IViewDataContainer viewDataContainer, RouteCollection routeCollection)
          : base(viewContext, viewDataContainer, routeCollection)
        {
          this._viewData = new ViewDataDictionary<TModel>(viewDataContainer.ViewData);
        }
      }
    }
    

    As we see, the ViewData is instantiated from some viewDataContainer in HtmlHelper constructor.

    Let’s try to see, how is this connected with the page:

    namespace System.Web.Mvc { 
    
        public abstract class WebViewPage<TModel> : WebViewPage {
    
            // some code
    
            public override void InitHelpers() {
                base.InitHelpers(); 
    
                // ...
    
                Html = new HtmlHelper<TModel>(ViewContext, this);
            } 
    
           // some more code
        }
    }
    

    So the current page is the viewDataContainer.

    So, we see, that a new instance of a ViewData dictionary is instantiated for HtmlHelper based on the dictionary, which is stored in View. The only option, which could make the two be kinda same, if they used same Disctionary internally. Let’s check that.

    Here is ViewData constructor:

        public ViewDataDictionary(ViewDataDictionary dictionary) 
        {
            if (dictionary == null) { 
                throw new ArgumentNullException("dictionary");
            } 
    
            foreach (var entry in dictionary) {
                _innerDictionary.Add(entry.Key, entry.Value); 
            }
            foreach (var entry in dictionary.ModelState) {
                ModelState.Add(entry.Key, entry.Value);
            } 
    
            Model = dictionary.Model; 
            TemplateInfo = dictionary.TemplateInfo; 
    
            // PERF: Don't unnecessarily instantiate the model metadata 
            _modelMetadata = dictionary._modelMetadata;
        }
    

    As we can see, entries a just copied, but a different underlying _innerDictionary is used.

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

Sidebar

Related Questions

Just wondering what little scripts/programs people here have written that helps one with his
Just wondering what the difference between BeginInvoke() and Invoke() are? Mainly what each one
Just wondering what the difference between MFC control messages prefixed with the following is:
just wondering if anyone knows of a truly restful Put/delete implementation asp.net mvc preview
Just wondering where is best to put functionality in an MFC application that is
i was just wondering, if i wanted to reset the actual preference file used
I'm just wondering how folks unit test and assert that the expected collection is
I am wondering if there is any difference in runtime between a generic container
I'm wondering this because it's just dawned on me that I've never been involved
Just wondering if a .NET app can be compiled down to native machine code

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.