我正在尝试填充办公地点(文字)和地址(价值)的下拉列表 在显示页面后在浏览器中查看我的页面源时,我可以看到select(下拉列表)选项值都是<!> quot; <!> quot;。这是我的代码。我正在使用LinqToSql数据上下文调用来获取SelectList的数据。在调试器中,我可以看到从我的呼叫返回的列表确实具有我需要的地址和办公室位置。 我的模型datacontext代码:

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();
    }

我的观看代码:          <!> lt;%= Html.DropDownList(<!> quot; locations <!> quot;,(SelectList)ViewData [<!> quot; OfficeLocations <!> quot;])%<!> gt;

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top