我想问你一个关于从2下拉列表中过滤数据的问题。
首先,我有一个下拉列表,其中包含两种类型的人员" Phisic"和#34;自然"另一个包含人的性别"未知","女","男"。
如果我选择" Natural"重视另一个下拉列表我只想显示2个性别"男性"和"女性"。
如何使用linq和kendoUi()下拉列表
这是我的代码
The controller that takes the gendertypes:
vm.GenderTypes = _commonService.GetLocalizedDictionaryItems(DictionaryCodes.GenderType).ToList();
public static IQueryable<NamedItem> GetLocalizedDictionaryItems(this CommonService service, string dictionaryCode, params string[] itemCodes)
{
var q = service.GetDictionaryItems(dictionaryCode);
if( itemCodes.Length > 0 )
q = q.Where(a => itemCodes.Contains(a.Code));
return (from a in q
let name = GetCurrentLanguageField(a.NameAB, a.NameEN, a.NameSB)
orderby name
select new NamedItem()
{
Id = a.Id,
Name = name
}).UnwrapLocalizedQuery();
}
&#13;
This code is for gender types
@if( Model.CanSave )
{
@Html.LabelFor(m => m.GenderId)
@(Html.Kendo().DropDownListFor(m => m.GenderId)
.BindTo(Model.GenderTypes)
.DataTextField("Name")
.DataValueField("Id")
)
}
else
{
if(Model.IsNatural){
@Html.LabelFor(m => m.GenderId)
<span class="readonly">@Html.DisplayDashFor(m => m.GenderName)</span>
}
}
This code is for types of person;
@Html.LabelFor(m => m.IsNatural)
@if( Model.CanSave )
{
@(Html.Kendo().DropDownListFor(m => m.PersonTypeCode)
.BindTo(new[] { new { Id = "natural", Name = Resx.PersonDetails.Natural }, new { Id = "legal", Name = Resx.PersonDetails.Legal } })
.DataTextField("Name")
.DataValueField("Id")
)
}
else
{
<span class="readonly">@(Model.IsNatural ? Resx.PersonDetails.Natural : Resx.PersonDetails.Legal)</span>
}
&#13;