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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:25:02+00:00 2026-05-11T20:25:02+00:00

My MVC application contains a parent model, which will contain 1 or more child

  • 0

My MVC application contains a parent model, which will contain 1 or more child models.

I have set up the main view to display properties from the parent model, and then loop through a collection of my child models (of various types, but all inheriting from the same base type). Each of the child models have a corresponding partial view.

My “parent” view iterates over the child models like this:

foreach (ChildBase child in ViewData.Model.Children)
{
  Html.RenderPartial("Partials/"+child.ChildType.ToString()+"Child", 
    section);
}

My application has the appropriate /Partials/ChildType1.ascx, ChildType2.ascx, etc. Everything works great.

  1. Is this an appropriate way to use Partial Views? It feels slightly off-kilter due to the dynamic names, but I don’t know another way to perform dynamic selection of the proper view without resorting to a big switch statement.

  2. Is it advisable to use the same view for multiple “modes” of the same model? I would like to use the same .ascx for displaying the “read only” view of the model, as well as an edit form, based on which Controller Action is used to return 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-11T20:25:02+00:00Added an answer on May 11, 2026 at 8:25 pm

    Iconic,

    It’s difficult to answer the questions without knowing exactly what you’re trying to achieve.

    I’ll have a go though:

    If you’re familiar with web forms, think of your partial view as a webforms usercontrol for the moment and think of the part of your model that is relevant to your partial views as a ‘fragment of information’ that want to pass across to the partial view.

    Natural choices for using a partial view would be for elements used in many views across your site.

    So … in answer:

    1.Although what you are doing is valid, it doesn’t seem quite correct. An example of a partial view I have used might be a row in a grid of data where you’d call the partial view passing in the row object as its model:

        foreach (MyObject o in Model.objects)
    {
      Html.RenderPartial("Shared/gridRowForObject.ascx", o, ViewData);
    }
    

    You can strongly type your views also to expect a specific type to be passed through as the Model object.

    Again another use might be a login box or a ‘contact me form’ etc.

    2._Ultimately this is a personal design decision but I’d go for the option that requires the least application/presentation logic and the cleanest code in your view. I’d tend to avoid writing to many conditional calls in your view for example and by inferring a base type to pass across to all of your partial views as in your example, may well tie you down.

    When learning the MVC framework I found the Oxite code to be useful.

    I hope that helps.

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

Sidebar

Ask A Question

Stats

  • Questions 235k
  • Answers 235k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Because your rule only applies if a / is added… May 13, 2026 at 6:08 am
  • Editorial Team
    Editorial Team added an answer Make sure you use Eclipse PDE (plugin development environment), this… May 13, 2026 at 6:08 am
  • Editorial Team
    Editorial Team added an answer I was curious if this was the best practice when… May 13, 2026 at 6:08 am

Related Questions

I'm new to nHibernate, and trying to get my head around the proper way
I have two tables that I want to fetch data from. Lets call them
I am working on an ASP.NET MVC application that contains a header and menu
Scenario: I have a partial view that is used in several places across my

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.