【问题标题】:Dropdownlist value not getting set from SelectList passed to view in ViewData下拉列表值未从 SelectList 中设置,传递给 ViewData 中的视图
【发布时间】:2009-03-04 14:36:06
【问题描述】:

我正在尝试填充办公地点(文本)和地址(值)的下拉列表 在显示页面后在浏览器中查看我的页面源时,我可以看到选择(下拉列表)选项值都是“”。这是我的代码。我正在使用 LinqToSql 数据上下文调用来获取 SelectList 的数据。在调试器中,我可以看到从我的调用返回的列表确实包含我需要的地址和办公地点。 我的模型数据上下文代码:

public partial class uls_dbDataContext
{
    public List<office_location> GetOfficeLocations()
    {
        return office_locations.ToList();
    }
}

我的控制器代码:

    public ActionResult Directions()
    {
        uls_dbDataContext ulsdb_dc = new uls_dbDataContext();

        ViewData["OfficeLocations"] = new SelectList(ulsdb_dc.GetOfficeLocations(),"location_address", "location_name");

        ViewData["Title"] = "Directions";

        return View();
    }

我的查看代码:

【问题讨论】:

    标签: model-view-controller drop-down-menu null viewdata selectlist


    【解决方案1】:

    我必须从预览版 4 升级到 MVC RC2。它解决了下拉列表问题并修复了我的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多