I am trying to populate a dropdownlist and am getting a 500 error. CS0746: Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.
ViewModel:
public class InterestViewModel
{
public IEnumerable<SelectListItem> loanNames { get; set; }
}
Controller:
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();
}
View:
@Html.DropDownList("types", new SelectList(Model.loanNames, "Value", "Text"), new {multiple="multiple", data-placeholder="Select loan types" });
If you want a data attribute rendered try:
new { multiple = "multiple", data_placeholder = "Select loan types" }
The underscore will be treated as a -
when rendered, if I recall correctly.