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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:58:44+00:00 2026-05-22T14:58:44+00:00

I have the following class and editor template for creating a dropdownlist for various

  • 0

I have the following class and editor template for creating a dropdownlist for various currencies.

public class Currency
{
    public string CurrencyId { get; set; }
    public string CurrencyName { get; set; }
}

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<List<morkyc.Core.Model.Currency>>" %>

<tr>
    <td style="width:50%;">
    <label class="fieldLabel">
    Specify Currency :
    </label>
    </td>
    <td>
        <%= Html.DropDownListFor(model => model, new SelectList(Model, "CurrencyId", "CurrencyName", ))%>
     </td>
</tr>

I create a list in my controller

 List<Currency> lCurrencyList = new List<Currency>(new Currency[]
        {
            new Currency{CurrencyId = "AED", CurrencyName = "United Arab Emirates Dirham (AED)"}, 
            new Currency{CurrencyId = "AFN", CurrencyName = "Afghan Afghani (AFN)"}, 
            new Currency{CurrencyId = "ALL", CurrencyName = "Albanian Lek (ALL)"}, 
            new Currency{CurrencyId = "AMD", CurrencyName = "Armenian Dram (AMD)"}, 
            new Currency{CurrencyId = "ANG", CurrencyName = "Netherlands Antillean Guilder (ANG)"},
            new Currency{CurrencyId = "AOA", CurrencyName = "Angolan Kwanza (AOA)"},
            new Currency{CurrencyId = "ARS", CurrencyName = "Argentine Peso (ARS)"}, 
            new Currency{CurrencyId = "AUD", CurrencyName = "Australian Dollar (AUD)"}, 
            new Currency{CurrencyId = "AWG", CurrencyName = "Aruban Florin (AWG)"}, 
            new Currency{CurrencyId = "AZN", CurrencyName = "Azerbaijani Manat (AZN)"}, 
            new Currency{CurrencyId = "BAM", CurrencyName = "Bosnia-Herzegovina Convertible Mark (BAM)"}, 
            new Currency{CurrencyId = "BBD", CurrencyName = "Barbados Dollar (BBD)"}, 
            new Currency{CurrencyId = "BDT", CurrencyName = "Bangladeshi Taka (BDT)"}, 
            new Currency{CurrencyId = "BGN", CurrencyName = "Bulgarian Lev (BGN)"},
new Currency{CurrencyId = "ZWD", CurrencyName = "Zimbabwe Dollar (ZWD)"}
        });

In my view i call the following view to create the dropdownlist

<%= Html.EditorFor(model => model.Currency)%>

This is working perfectly fine.

Could anybody please suggest as to how can i set the default selected item ?

  • 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-22T14:58:45+00:00Added an answer on May 22, 2026 at 2:58 pm

    Your editor template is strongly typed to a currency list. Also you are passing a list as first argument to the DropDownListFor helper which is not good. You are never passing some selected value, so the best you could do in this editor template is to set the value to the first element of this list for example.

    <%= Html.DropDownListFor(
        model => model, 
        new SelectList(Model, "CurrencyId", "CurrencyName", "AED")
    )%>
    

    But I guess that you want to dynamically pass this value. So I would modify your view model a little:

    public class CurrencyViewModel
    {
        public string SelectedCurrency { get; set; }
        public IEnumerable<SelectListItem> Currencies { get; set; }
    }
    

    then have the following editor template:

    <%@ Control 
        Language="C#" 
        Inherits="System.Web.Mvc.ViewUserControl<CurrencyViewModel>" %>
    
    <tr>
        <td style="width:50%;">
            <label class="fieldLabel">
                Specify Currency :
            </label>
        </td>
        <td>
            <%= Html.DropDownListFor(
                model => model.SelectedCurrency, 
                new SelectList(Model.Currencies, "Value", "Text")
            )%>
         </td>
    </tr>
    

    and now in your controller:

    public ActionResult Foo()
    {
        var model = new CurrencyViewModel
        {
            // Define the selected value here
            SelectedCurrency = "AED",
            Currencies = new[]
            {
                new SelectListItem { Value = "AED", Text = "United Arab Emirates Dirham (AED)" }, 
                new SelectListItem{ Value = "AFN", Text = "Afghan Afghani (AFN)"}, 
                ...
            }
        };
        return View(model);
    }
    

    and finally in the view invoke the custom editor template:

    <%= Html.EditorForModel() %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class public class Car { public Name {get; set;} }
I have the following model: public class Person { public string Name { get;
I have the following class: public abstract class AbstractParent { static String method() {
I have the following editor template @model DateTime? @Html.TextBox(, (Model.HasValue ? Model.Value.ToShortDateString() : string.Empty),
Say I have the following models: public class Item { public int Id{ get;
I have a custom class: public class Person { public String Name { get;
I have an entity with the following attributes public class DimensionElement { public string
I have following class public class ButtonChange { private int _buttonState; public void SetButtonState(int
I have following class (as seen through reflector) public class W : IDisposable {
I have following test class @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {/services-test-config.xml}) public class MySericeTest { @Autowired

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.