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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:08:34+00:00 2026-05-27T18:08:34+00:00

I’m using MVC3, with the Razor syntax, and am going over an example in

  • 0

I’m using MVC3, with the Razor syntax, and am going over an example in the Apress book “Pro ASP.Net MVC 3 Framework” (which is very good). In it the author has this bit in a _Layout.cshtml file:

<body>
    <div id="header">
        @{Html.RenderAction("Summary", "Cart");}
        <div class="title">SPORTS STORE</div>
     </div>
     <div id="categories">
        @{ Html.RenderAction("Menu", "Nav"); }
     </div>
     <div id="content">
        @RenderBody()
    </div>
</body>

My question has to do with the CartController class. I see that it’s passed a Cart object in its constructor, but the code in the _Layout.cshtml snippet above doesn’t appear to pass one in when RenderAction() is called?

CartController snippet:

public ViewResult Summary(Cart cart) {
    return View(cart);
}

When I debug that method a Cart object is in fact passed in, but I don’t see where it’s coming from. This sample code uses Ninject as a dependency injection container but I can’t find any evidence in the configuration that it knows anything about the Cart class. Is there a ‘default value’ mechanism in MVC?

  • 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-27T18:08:35+00:00Added an answer on May 27, 2026 at 6:08 pm

    Summary is an action method. It is not a constructor. Therefore, DI doesn’t have anything to do with this. Instead, what we are seeing is the behavior of the default model binder. That is to say, the model binder will analyze whatever parameters you declare for your action method and will attempt to populate these arguments with data derived from form or query string parameters and route values.

    In your particular scenario, since you are not passing in any route values to your Html.Action call, all it’s doing is instantiating the Cart class — if you inspect it you will presumably see that it’s empty (no properties have been set).

    However, if you were to pass route values into your Action call, it would populate that object. For example, if Cart contained a property called “Size” of type int, and your action call looked like:

    @Html.Action("Summary", "Cart", new { Size = 5 })
    

    Your Cart class would now have its Size property set to 5.

    (Note also that it’s far cleaner to use the Action method and not the RenderAction method in this case. As you’ve seen, RenderAction assumes a statement-level call, which requires those ugly enclosing curly braces. Action on the other hand is an expression and returns the actual HTML content inline, and thus can be expressed in a more concise fashion.)

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

Sidebar

Related Questions

I've read a couple of articles on using asp.net mvc3 razor (which I am
I had created a webpage using asp.net mvc3 razor. I have two master pages
I have a string created using asp.net MVC3 Razor block like this: @{ var
I am creating a new web application using ASP.NET MVC3 Razor and HTML 5.
I'm using jquerymobile and asp.net MVC3 razor. I'm somewhat new to this, but figuring
I'm using ASP.NET MVC 3 with the Razor template engine for my website. I
I have an existing SqlConnection conn; in some controller (using ASP.NET MVC3 + Razor
I’m using MVC3 (with Razor Syntax). Here’s what I’m going for: part of my
I am trying to learn MVC using ASP.NET MVC3. Most of the tutorials I
I'm using ASP.NET MVC3 with razor engine.I want to apply css class on body

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.