c# - show distinct item in a dropdownlistfor in mvc -
i using following code bind dropdownlist. foliodividentlist can have multiple values. want bind unique values not able wrong please help.
@html.dropdownlistfor(model => model.buymorelist[i].foliono, new selectlist(model.buymorelist[i].foliodividendlist.select(x => new selectlistitem { value = x.foliono.tostring(), text = x.foliono }).distinct(), "value", "text")
try this:-
@html.dropdownlistfor(model => model.buymorelist[i].foliono, new selectlist(model.buymorelist[i].foliodividendlist.groupby(x => x.foliono) .select(x => { var firstset = x.first(); return new selectlistitem { value = firstset.foliono.tostring(), text = firstset.foliono }; } ),"value", "text")
Comments
Post a Comment