MVC RadioButtonFor在枚举时检查,但在viewmodel中不检查int

时间:2013-08-09 22:12:12

标签: asp.net-mvc

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

视图模型:

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

Enum:

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属性,enumPaymentOption不应该相同吗?

0 个答案:

没有答案
相关问题