dropdownlistfor - 从ienumerable模型中选择不同的列 [英] dropdownlistfor - select distinct column from ienumerable model
问题描述
我必须在Dropdownlistfor中填充**不同的**公司名称来自
@model IEnumerable< zykod.data .models.cutilitymodel>
我试过以下方式。什么都行不通。感谢您的帮助。
1. @ Html.DropDownListFor(Model.Select(i => i.CompanyName).Distinct()。ToList(),new List< SelectListItem>(),new {@class =input-large form-control})
2. @ Html.DropDownList(CompanyName,new SelectList(Model).Distinct())
3. @ Html.DropDownListFor(model => model.CompanyName,new List< SelectListItem>(),new { @class =input-large form-control})
谢谢
Karthey
Hi ,
I have to populate **distinct** company name in Dropdownlistfor from
@model IEnumerable<zykod.data.models.cutilitymodel>
I tried the following way. Nothing is working. Your help is appreciated.
1. @Html.DropDownListFor(Model.Select(i => i.CompanyName).Distinct().ToList(), new List<SelectListItem>(), new { @class = "input-large form-control" })
2. @Html.DropDownList("CompanyName", new SelectList(Model).Distinct())
3. @Html.DropDownListFor(model => model.CompanyName, new List<SelectListItem>(), new { @class = "input-large form-control" })
Thanks
Karthey
推荐答案
尝试这样的事情:
Try something like this:
@Html.DropDownListFor(model => model.CompanyName, new SelectList(Model.Select(i => i.CompanyName).Distinct()), new { @class = "input-large form-control" })
我试过并且
got the following error:
<pre lang="xml">CS1061: 'System.Collections.Generic. CS1061: 'System.Collections.Generic.IEnumerable<Zykod.Data.Models.CUtilityModel>'
does not contain a definition for 'CompanyName' and no extension method 'CompanyName' accepting a first
argument of type 'System.Collections.Generic.IEnumerable<Zykod.Data.Models.CUtilityModel>' could be found
(are you missing a using directive or an assembly reference?) ' does not contain a definition for 'CompanyName'
and no extension method 'CompanyName'
accepting a first argument of type 'System.Collections.Generic.IEnumerable<Zykod.Data.Models.CUtilityModel>'
could be found (are you missing a using directive or an assembly reference?)</pre>
这篇关于dropdownlistfor - 从ienumerable模型中选择不同的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!