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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:31:13+00:00 2026-06-01T18:31:13+00:00

This is not that important, but I’m getting conflicting information about this so I

  • 0

This is not that important, but I’m getting conflicting information about this so I thought of ask here.

Let’s say I have a simple Controller and I want to pass the Model to the View. Most of the time I see it like this:

[HttpGet]
public ActionResult Foo() {
    var bar = new SomeModel() {
        Id = 1,
        Name = "John Dork",
        Email = "some@email.something"
    };
    ViewData.Model = bar;
    return View();
}

Or like this:

[HttpGet]
public ActionResult Foo() {
    var bar = new SomeModel() {
        Id = 1,
        Name = "John Dork",
        Email = "some@email.something"
    };
    return View(bar);
}

Questions: Although I’m not aware of a difference between these two ways of sending this data to the view, is there in fact a difference? And what is different about them? What would be the “correct” way of doing this?

Thanks

  • 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-06-01T18:31:14+00:00Added an answer on June 1, 2026 at 6:31 pm

    They are equivalent. In the MVC source code, View(object) is defined as:

        protected internal ViewResult View(object model)
        {
            return View(null /* viewName */, null /* masterName */, model);
        }
    

    Which in turns calls:

        protected internal virtual ViewResult View(string viewName, string masterName, object model)
        {
            if (model != null)
            {
                ViewData.Model = model;
            }
    
            return new ViewResult
            {
                ViewName = viewName,
                MasterName = masterName,
                ViewData = ViewData,
                TempData = TempData,
                ViewEngineCollection = ViewEngineCollection
            };
        }
    

    And you can see that it just sets ViewData.Model.

    There’s no “correct” way of doing it, but I feel that the second approach (i.e., not using ViewData.Model) is more fluent and pleasing.

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

Sidebar

Related Questions

I see this question here on SO but I am not sure that answers
Please not that I fully understand this is a dumb ass idea, but its
Not that I would ever need to do this, but I want to understand
This is really stumping me today. I'm sure its not that hard, but I
This is not a technical question, but given that there are a few iPhone
I have several files (they are XML but that's not important) that need to
It's not that I can't google for myself, however others have tread this path
So why is this not working? I'm creating a regex that will match a
Please note that this is not homework and i did search before starting this
This is not an actual Xcode error message, it is a warning that has

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.