【发布时间】:2019-02-22 23:30:30
【问题描述】:
我的页面中有dropdown 列表,它使用enum 列表进行绑定。
我的enum 看起来像
public enum PaymentType
{
/// <summary>
/// The Cash
/// </summary>
Cash = 0,
/// <summary>
/// The Credit
/// </summary>
Credit = 1,
/// <summary>
/// The Debit
/// </summary>
Debit = 2
}
我将此枚举绑定到下拉列表,如下所示
<select class="select-text" id="paymentType" asp-
for="PurchaseOrder.PaymentType" required asp-items="@(new
SelectList(Model.PaymentTypes, "Id", "Name"))">
<option selected="selected" value ="">--Select payment type--</option>
</select>
问题就像PurchaseOrder.PaymentType 是一个整数字段,所以这里的默认值是0,这使得我的dropdown 总是选择Cash。我知道使PurchaseOrder.PaymentType 可以为空是一种选择,但我希望归档为不可为空。
我已经厌倦了在选择中添加value="" 并在默认选项中尝试了selected="selected",但没有任何效果。
有人可以帮我用标签助手语法解决这个问题吗?
【问题讨论】:
标签: c# asp.net-core asp.net-core-mvc asp.net-core-tag-helpers