【问题标题】:not sure why this RadioButton isn't giving the proper value不知道为什么这个 RadioButton 没有给出正确的值
【发布时间】:2014-08-03 03:54:04
【问题描述】:

我有一个 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);
}

【问题讨论】:

  • 不相关,但您应该将所有
  • 放在
      标签下
  • 我现在已经修复了
      标签
  • 标签: c# asp.net-mvc radio-button


    【解决方案1】:

    在你看来,改变你的 foreach

     <div>
         <b>Facility Type *:</b>
         <ul>
             @foreach (string facility in Model.RoadwayTypeRadioButton)
             {
                 <li>
                     @Html.RadioButton("roadwayTypeButton", facility) @facility
                 </li>
             }
         </ul>
     </div>
    

    【讨论】:

      猜你喜欢
      相关资源
      最近更新 更多
      热门标签