我有一个EF模型,我从中提取数据。当我跟踪它时,我可以看到它获得正确的值,但是我的C#代码有问题,因为它没有显示单选按钮中的值。
你能看出我做错了吗?
型号:
public class SearchPageModel
{
...
public IEnumerable<string> RoadwayTypeRadioButton { get; set; }
...
// populate radio buttons
public IEnumerable<string> populatRadioList()
{
var query = (from d in myContext.lkp_roadwaytypes
select d.roadwaytype).ToList().Distinct();
return query;
}
}
查看:
<div>
<b>Facility Type *:</b>
@foreach (var facility in Model.RoadwayTypeRadioButton)
{
<ul>
<li>
@Html.RadioButton(facility, "0")
</li>
</ul>
}
</div>
控制器:
public ActionResult Search()
{
SearchPageModel spm = new SearchPageModel();
spm.RoadwayTypeRadioButton = spm.populatRadioList();
return View(spm);
}
答案 0 :(得分:2)
在您看来,改变你的foreach
<div>
<b>Facility Type *:</b>
<ul>
@foreach (string facility in Model.RoadwayTypeRadioButton)
{
<li>
@Html.RadioButton("roadwayTypeButton", facility) @facility
</li>
}
</ul>
</div>