0

今天在尝试解决我遇到的问题时注意到了一件新事物。

视图模型:

[Required]
public PaymentOption PaymentOption { get; set; }

枚举:

public enum PaymentOption
{
    CreditCard,
    Invoice
}

看法:

<div>
    @Html.RadioButtonFor(x => x.PaymentOption, PaymentOption.CreditCard, new Dictionary<string, object> {{ "id" , "cc" }}) Credit Card
    @Html.RadioButtonFor(x => x.PaymentOption, PaymentOption.Invoice, new Dictionary<string, object> {{ "id" , "in" }}) Invoice
</div>

如果我现在将PaymentOption属性更改int为默认情况下在呈现视图时不会选中任何单选按钮。

public int PaymentOption { get; set; }

如果PaymentOption属性是PaymentOption枚举,则默认选中其中一个单选按钮,并且在 html 源中,输入单选具有checked=checked.

public PaymentOption PaymentOption { get; set; }

为什么会有这种行为?int两者和财产enum不应该相同吗?PaymentOption

4

0 回答 0