如何在下拉列表中添加类

时间:2016-04-12 09:34:49

标签: c# asp.net-mvc

我有不同的下拉列表,我想使用相同的样式。一个下拉列表已动态加载。

@foreach (var x in Model)
{
    <div class="form-group">
        <label class="col-md-6">@x.Question</label>
        <div class="col-md-6">
            @switch (x.QuestionTypeId)
            {
                case 1:
                {
                    @Html.DropDownList("Question_" + @x.QuestionId, x.PossibleAnswers, "Please select", new { @class = "form-control", required = "required" })
                }
                break; 
            }

我想在下面的下拉列表中加载相同的样式,如您所见;我试图运行时出现此错误

  

错误:无法转换为&#39; string&#39; to&#39; System.Collections.Generic.IEnumerable&lt; System.Web.Mvc.SelectListItem&gt;

<div class="form-group">
    <label class="col-md-2">Reviewer</label>
    <div class="col-md-3">
        @Html.DropDownList("Reviewer", "Select a Reviewer", new { @class = "form-control", required = "required" })
    </div>
    <label class="col-md-2">Line of Business</label>
    <div class="col-md-3">
        @Html.DropDownList("LineOfBusiness", "Select a Value", new { @class = "form-control", required = "required" })</div>
    </div>
</div>

0 个答案:

没有答案