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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:03:03+00:00 2026-06-15T15:03:03+00:00

I need to create a view that displays Order Header information and I need

  • 0

I need to create a view that displays Order Header information and I need to add a patial view that displays a grid of Line Items. The partial view will be strongly typed from a viewmodel. I understand that I should use the html helper @Html.Partial(“Path/view”). I have only used controllers up til now to open a view, populating the viewmodel before sending it to the view. Since the partial view is being called form the html helper, I would like to know is what would be the best way to populate the parital view with the model data.

  • 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-15T15:03:04+00:00Added an answer on June 15, 2026 at 3:03 pm

    Option 1: Inherit from parent page

    By default, any partial view rendered by calling @Html.Partial("PartialViewName") will get the view model passed to the parent view.

    So if you have:

    View Model

    namespace MyNamesapce
    {
        public OrderInfoViewModel
        {
            public string OrderTitle { get; set; }
            public IEnumerable<OrderItem> OrderItems { get; set; }
        }
    }
    

    OrderInfo.cshtml

    @model MyNamespace.OrderInfoViewModel
    
    <h1>@Model.OrderTitle</h1>
    
    @Html.Partial("OrderLineItems")
    

    The OrderLineItems page should get a MyNamespace.OrderViewModel passed to it… so your partial view should look like this:

    OrderLineItems.cshtml

    @model MyNamespace.OrderInfoViewModel
    
    foreach (var orderItem in Model.OrderItems)
    {
        //Do stuff
    }
    

    Option 2: Specify model

    You can use the second parameter to specify the view model to be passed. I.e.

    OrderInfo.cshtml

    @model MyNamespace.OrderInfoViewModel
    
    <h1>@Model.OrderTitle</h1>
    
    @Html.Partial("OrderLineItems", Model.OrderItems)
    

    OrderLineItems.cshtml

    @model IEnumerable<OrderItem>
    
    foreach (var orderItem in Model)
    {
        //Do stuff
    }
    

    Option 3: Use partial actions

    If you need to reuse a partial view over multiple pages, it could be a good idea to use a partial view to eliminate having to populate different view models with the same info just because the page is going to be using the same partial.

    E.g.

    View Model

    namespace MyNamesapce
    {
        public OrderInfoViewModel
        {
            public string OrderTitle { get; set; }
        }
    }
    

    Controller

    public class OrderController : Controller
    {
        public ActionResult OrderInfo(int orderId)
        {
            OrderInfoViewModel viewModel = GetViewModel(orderId);
            return View(viewModel);
        }
    
        public PartialViewResult OrderLineItems(int orderId)
        {
            IEnumerable<OrderItem> orderItems = GetOrderItems(orderId);
            return Partial(orderItems);
        }
    }
    

    OrderInfo.cshtml

    @model MyNamespace.OrderInfoViewModel
    
    <h1>@Model.OrderTitle</h1>
    
    @Html.Action("OrderLineItems")
    

    OrderLineItems.cshtml

    @model IEnumerable<OrderItem>
    
    foreach (var orderItem in Model.OrderItems)
    {
        //Do stuff
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a View that represents an x/y axis. I will read
I understand that we need to create MXML file to define a view. Suppose
I need to create a custom view, which extends RelativeLayout and simply needs to
In my app, I create view controller objects as I need them. When a
UPDATED: I am using MySQL statement to create a view: I need to show
I have a table view that displays a list that I want the user
I have a View with a form which displays data from objects that are
I have 3-tier EJB application, and I need to create a view on a
I have a table view that displays custom cells, the cells contain an image
As need to display Records in grid view in (ASP.NET) web site. and for

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.