У меня есть следующий класс и шаблон редактора для создания выпадающего списка для различных валют.
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>
Я создаю список в моем контроллере
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)"}
});
На мой взгляд, я вызываю следующий вид для создания выпадающего списка
<%= Html.EditorFor(model => model.Currency)%>
Это прекрасно работает.
Может ли кто-нибудь предложить, как установить выбранный по умолчанию элемент?