dropdownlistfor - 从ienumerable模型中选择不同的列 [英] dropdownlistfor - select distinct column from ienumerable model

查看:161
本文介绍了dropdownlistfor - 从ienumerable模型中选择不同的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我必须在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: &#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>


这篇关于dropdownlistfor - 从ienumerable模型中选择不同的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆