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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:20:56+00:00 2026-05-15T21:20:56+00:00

Summary: If you use ASP.NET MVC 2’s templates to render a DropDownList, how would

  • 0

Summary:

If you use ASP.NET MVC 2’s templates to render a DropDownList, how would you access the list of options if they are stored in the top level View’s Model.property? Also, is there some [DataAnnotation] way to associate this list? Links to examples would be very helpful.

Background:

In ASP.NET MVC 2, you can create a custom class like StateName and use an EditorTemplate called StateName.ascx, which will display that partial view anytime it finds a StateName property. Brad Wilson has a great write-up here describing it. These partial view templates can be nested so that each template only deals with it’s own scope (matching the template’s scope to the matching POCO’s properties).

Setup:

Now imagine that the StateName.ascx renders a DropDownList and needs the list of possible states ([{“AL”,”Alabama”},{“PA”,”Pennsylvania”},…]). Generally, the top level View Model has all we need to render both the DomainModel (like our ShoppingCart), and any miscellaneous data like lists for drop downs.

Question:

So, the question is how does a partial view template StateName.ascx reference the non-partial top level view’s Model property IList<StateName> States to populate the DDL in the partial view template? (especially if you have several nested or deep dive renderings like Model.Customer[0].BillingAddress.State, the template’s parent view may not be the top level view).

Another angle may be to put some sort of [Data Annotation] on the class property that associates this list of possible states to the partial view template’s Model?

For example, here’s the top level View’s Model:

Model.ShoppingCart.Customer.ShippingAddress;
Model.ShoppingCart.Customer.BillingAddress;
Model.StateNames;         // IList<StateName>
Model.MaritalStatusNames; // IList<MaritalStatus>
Model.GenderNames;        // IList<Gender>

Furthermore we could make all DDL data lists in one property, like Model.DDLs.StateNames, Model.DDLs.GenderNames, etc.?

  • 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-15T21:20:56+00:00Added an answer on May 15, 2026 at 9:20 pm

    I think the short answer is that the partial template cannot access the parent’s entire Model because it only receives the sub-model that it’s meant to work with.

    In your case (i.e. global lists of things that don’t change) you could always declare your list in a static property on some helper object so that you don’t need a model instance to be able to access it. For example your Address object could have a static list of all states.

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

Sidebar

Related Questions

No related questions found

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.