【发布时间】:2014-03-12 14:31:48
【问题描述】:
下面的代码在没有这一行的情况下完美运行:“.Insert(0, new SelectListItem(){Text = "", Value="", Selected = false})"...基本上我想添加一个空白下拉列表的值,我得到的错误是“无法从 void 转换为 SelectListItem。”关于如何正确添加空白的任何想法?
@Html.DropDownListFor(model => model.itemPost.txtVal,
new List<SelectListItem>(
(from node in
System.Xml.Linq.XDocument.Parse(Model.itemQuestionRowDef.SupportingXML).Descendants("option")
select new SelectListItem
{
Text = node.Value,
Value = node.Attribute("value").Value,
Selected = node.Attribute("value").Value == Model.itemPost.txtVal ? true : false
}
)
).Insert(0, new SelectListItem(){Text = "", Value="", Selected = false}),
new { @class = "tobeFilled", id = "id_" + Model.counter, Name = "questionLst[" + Model.counter + "]." + "txtVal" })
【问题讨论】:
标签: c# asp.net-mvc linq