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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:37:39+00:00 2026-05-17T21:37:39+00:00

I have a view that renders a few drop downs on it. These are

  • 0

I have a view that renders a few drop downs on it. These are built from IDictionary’s.

When I render a view and I want to show the currently selected value of one of these options, I want to see how to convert the number in my view into the string value in the dictionary.

I got quite far with this (as my dictionary starts from 0) but it doesn’t quite work.

<%= Html.Encode(Chart.TypeDictionary.ElementAt(Model.iType)) %>

this returns this

[Public, 0]

Presumably I can just get the value on the left?

Does anyone have a better solution to this, and also what is the best way to do it when you don’t have drop downs.

I have used enums before, but obviously you can’t have spaces in them.

  • 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-17T21:37:40+00:00Added an answer on May 17, 2026 at 9:37 pm

    Does this not work?

    <%= Html.Encode(Chart.TypeDictionary.ElementAt(Model.iType)).Key %>
    

    Edit

    Without more context, I can’t give you a definitive answer on what I’d consider to be the best way to go about this. When I’m displaying a dropdown list, I’ll often store the options in the view model in a form that will make it easy to create the dropdown. For example:

    <%=Html.DropDownList("chartType", 
                         Model.ChartTypes.Select(
                             ct => new SelectListItem
                                   {
                                       Selected = Model.iType == ct.Value,
                                       Value = ct.Value,
                                       Text = ct.Name
                                   })%>
    

    However, if you’re using the same model as an input value to your controller action, this won’t work. In that case, I’d store the options in the ViewData. If you’re representing an enum value type, one option is to create an extension method that takes the enum type in question, along with the current value, and creates a dropdown list for you. If you follow the CamelCase convention in your enum values, you can simply have this method put a space between lower-case and upper-case letters. (e.g. CamelCase => “Camel Case”).

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

Sidebar

Related Questions

I have a view that I want to add some custom drawing to. I
I have a view that has a list of jobs in it, with data
I have a View that can vary significantly, depending on the 'mode' a particular
I have a view that is joining two tables and ordering by the first
Image i have a view that is cached with the OutputCache attribute but i
How does your employer limit/prevent pirating of its products? Some have the view that
I have a list view that is periodically updated (every 60 seconds). It was
I have a view user control that can post form. This control can be
I have a view using a master page that contains some javascript that needs
We have a View (call it X) that is the base view called by

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.