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 106k
  • Answers 106k
  • 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 Web servers often return an error page with more details… May 11, 2026 at 8:51 pm
  • Editorial Team
    Editorial Team added an answer First, the Law of Demeter, like most rules of programming,… May 11, 2026 at 8:51 pm
  • Editorial Team
    Editorial Team added an answer The POSIX version of make does not explicitly support file… May 11, 2026 at 8:51 pm

Related Questions

I need to reask my old question, I probably shouldnt have asked it at
This should be a really really simple thing, but for some reason it is
(Scroll down to bottom of post to find solution.) Got a asp.net page which
I can't seem to be able to disable ViewState for controls that I add

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.