Html助手Dropdownlist

时间:2015-07-15 14:55:23

标签: c# html-helper html.dropdownlistfor

我正在尝试填充下拉列表并收到500错误。 CS0746:无效的匿名类型成员声明符。必须使用成员分配,简单名称或成员访问声明匿名类型成员。

视图模型:

public class InterestViewModel 
{
    public IEnumerable<SelectListItem> loanNames { get; set; }  
}

控制器:

using (var db = new db2rwEntities())
{
    model = new InterestViewModel();
    model.loanNames = db.PRODUCTs.Where(x =>    
            Constants.autoLoanTypes.Contains(x.FXP_TYPE_NBR ?? 0) && 
            x.PRODUCT_CLASS_CODE == 2
    ).Select(x => new SelectListItem() { 
        Text = x.PRODUCT_NAME, 
        Value = x.PRODUCT_NAME 
    }).ToList();
}

查看:

@Html.DropDownList("types", new SelectList(Model.loanNames, "Value", "Text"), new {multiple="multiple", data-placeholder="Select loan types" });

1 个答案:

答案 0 :(得分:1)

如果要渲染数据属性,请尝试:

new { multiple = "multiple", data_placeholder = "Select loan types" }

如果我没记错,下划线在渲染时将被视为-