私が抱えている問題を解決しようとしているときに、今日新しいことに気づきました。
ビューモデル:
[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、ラジオボタンの 1 つがデフォルトでチェックされ、html ソースでは入力ラジオにchecked=checked.
public PaymentOption PaymentOption { get; set; }
なぜこの動作ですか?int両方とプロパティenumで同じであるべきではありませんか?PaymentOption