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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:14:42+00:00 2026-05-10T21:14:42+00:00

I need a dropdown list on my page that will allow a user to

  • 0

I need a dropdown list on my page that will allow a user to select their state. Since this is probably a control that will be used elsewhere, I thought it would be a good idea to create an MVC View User Control that could be reused.

I was thinking the control would look something like this:

<select name='' id=''>    <option value='AL'>Alabama</option>    <option value='AK'>Alaska</option> </select> 

And the code in my view would be something like:

<%= Html.RenderPartial('StateDropdownControl') %> 

My question is, what’s the best way to set the name and id on the control? I’d want to make sure I could have multiple instances of this control on one page, if needed. Also, I’d want to be able to send in the state that should be selected by default.

Would I do it with ViewData somehow?

  • 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. 2026-05-10T21:14:43+00:00Added an answer on May 10, 2026 at 9:14 pm

    Corey is on to the right solution. I think declaring specific Model objects for your view makes the views VERY simple and as a side bonus makes them dirt easy to test.

    So instead of just passing the ID as the object, you’d probably want to create your own Model object to pass in.

    It could look something like this:

    public class StateDropDownPresentationModel {     public string DropDownID { get; set; }     public string SelectedState { get; set; } } 

    Obviously, keep adding whatever you need to this model to make your view correct.

    Then, you could call it like this:

    <%= Html.RenderPartial('/someDirectory/SomeControl.ascx', new StateDropDownPresentationModel { DropDownID = 'MyID', SelectedState = 'IL' } %> 

    Then just make sure you put in checks for things like ID being null/blank (that should probably throw an error) and SelectedState being null/blank.

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

Sidebar

Ask A Question

Stats

  • Questions 62k
  • Answers 62k
  • 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
  • added an answer Change the call to the following Assert.IsInstanceOfType(0, typeof(int)); The first… May 11, 2026 at 10:06 am
  • added an answer You could bundle your application with its OS as an… May 11, 2026 at 10:06 am
  • added an answer In your code If e.Item.ItemType = ListItemType.Item Then Dim gvw… May 11, 2026 at 10:06 am

Related Questions

I need a dropdown list on my page that will allow a user to
In a drop down list, I need to add spaces in front of the
I need to create a form with, half linear view (textboxes and dropdownlists in
I have three values I need to align in a dropdown box. How can
I need a C# profiler. Although I'm not averse to paying for one, something
I need a database that could be stored network drive and would allow multiple
I need a JavaScript library that supports Ajax as well as help me in
I need a quick algorithm to select 5 random elements from a generic list.
I need a Regex that will match a java method declaration. I have come
I need a pseudorandom number generator algorithm for a assembler program assigned in a

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.