@Html.DropDownList("AgentId", null, htmlAttributes: new { @class = "form-control" })
代理列表来自一个名为AgentId的Viewbag,可以直接从数据库中读取。
Viewbag. AgentId = new Selectlist (db.Agents, "ID", "AgentCentre", distribution.AgentId)
发布于 2018-08-03 08:26:55
您可以使用此重载,它接受选项标签作为第三个参数
public static MvcHtmlString DropDownList(
this HtmlHelper htmlHelper,
string name,
IEnumerable<SelectListItem> selectList,
string optionLabel,
Object htmlAttributes
)
所以你的代码应该是
@Html.DropDownList("AgentId", null,"Select an agent", new { @class = "form-control" })
这将添加一个文本为"Select an agent“但没有值属性的选项。
https://stackoverflow.com/questions/51662629
复制相似问题