MVC在VIEW中动态控制htmlAttributes的方法

@{
IDictionary<string, object> dic = new Dictionary<string, object>();
dic.Add("class", "selectpicker");
dic.Add("data-style", "btn-co2;");
}
@Html.DropDownList("drpdept", (SelectList)ViewData["deptList"], "--Select One--", dic)

这个是直接在页面当中编写,@{} 代表中的代码相当于在后台代码写法

原文地址:https://www.cnblogs.com/it1042290135/p/6381580.html