ASP.NET MVC设置RadioButtonFor

时间:2013-10-23 22:39:04

标签: asp.net-mvc asp.net-mvc-4

MVC 4:

我有以下无线电控件

@Html.RadioButtonFor(o => o.TradeOrder.Exchange, "CA", new {id = "exchangeCA"})
@Html.RadioButtonFor(o => o.TradeOrder.Exchange, "US", new {id = "exchangeUS"})

o.TradeOrder.Exchange 是一个字符串,但不包含“CA”或“US”,因此我们覆盖如图所示。

如果 o.TradeOrder.Exchange ==“X”,如何设置CA无线电控件?

1 个答案:

答案 0 :(得分:0)

尝试

@Html.RadioButtonFor(o => o.TradeOrder.Exchange, "US", new {id = "exchangeUS"},new { Checked = (o.TradeOrder.Exchange=="X" ? "Checked" : string.Empty) )