我有以下行動方法,其中有一個viewBag與字符串列表: -無法將類型「System.Collections.Generic.List <string>」到「System.Web.Mvc.SelectList」
public ActionResult Login(string returnUrl)
{
List<string> domains = new List<string>();
domains.Add("DomainA");
ViewBag.ReturnUrl = returnUrl;
ViewBag.Domains = domains;
return View();
}
,並在視圖我想建立一個下拉列表,顯示viewBag字符串如下: -
@Html.DropDownList("domains",(SelectList)ViewBag.domains)
但我得到了以下錯誤: -
無法將類型「System.Collections.Generic.List」到 「System.Web.Mvc.SelectList」
因此,誰能adive爲什麼我不能填充蜇傷的名單我的下拉列表? 謝謝
你並不需要創建SelectList'的'一個實例。所有'DropDownList'需要的是'IEnumerable'。 –