Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted

Try something like this:
C#
@Html.DropDownListFor(model => model.CompanyName, new SelectList(Model.Select(i => i.CompanyName).Distinct()), new { @class = "input-large form-control" })
 
Share this answer
 
I tried and
XML
got the following error:
<pre lang="xml">CS1061: &#39;System.Collections.Generic. CS1061: &#39;System.Collections.Generic.IEnumerable&lt;Zykod.Data.Models.CUtilityModel&gt;&#39;
does not contain a definition for &#39;CompanyName&#39; and no extension method &#39;CompanyName&#39; accepting a first
argument of type &#39;System.Collections.Generic.IEnumerable&lt;Zykod.Data.Models.CUtilityModel&gt;&#39; could be found
(are you missing a using directive or an assembly reference?) &#39; does not contain a definition for &#39;CompanyName&#39;
 and no extension method &#39;CompanyName&#39;
accepting a first argument of type &#39;System.Collections.Generic.IEnumerable&lt;Zykod.Data.Models.CUtilityModel&gt;&#39;
could be found (are you missing a using directive or an assembly reference?)</pre>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900