ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
ComboBox entries "Undefined"
Title:
B
I
{code}
?
I am using a combobox as shown below: @(Html.Awe().AjaxRadioList("engineer").Value("Select Engineer").Combobox().Url(Url.Action("GetEngineerData", "TestData"))) My "GetEngineerData" controller method is shown below as well: public ActionResult GetEngineerData() { IQueryable<string> EngineerL = db.Results.Where(x => x.Engineer != null).Select(z => z.Engineer).Distinct().OrderBy(o => o); return Json(EngineerL); } Upon page load, the dropdown shows up but both entries in the dropdown have the text "undefined". Any help is appreciated. Thank you.
Save Changes
Cancel
eliawesome
asked at 22 Sep 2021
You need to return a collection of `KeyContent`, not a `string`, have a look at any of our demos, for example here: https://demo.aspnetawesome.com/Odropdown#odropdown
at 22 Sep 2021
Omu
I changed code to used KeyContent, and I am having trouble attempting to have a distinct list from the database. My code is below: var items = db.Results.ToList().Where(x=>x.Engineer != null).Select(o => new KeyContent(o.Engineer, o.Engineer)).Distinct(); I have also tried this: var items = db.Results.ToList().Where(x=>x.Engineer != null).Distinct().Select(o => new KeyContent(o.Engineer, o.Engineer)); No matter where I call the Distinct(), the list populates with duplicates. Any ideas on this?
at 22 Sep 2021
eliawesome
I have resolved this issue. Solution was: var items = db.Results .Where(x => x.Engineer != null) .Select(x => x.Engineer) .ToList() .Distinct() .Select(x => new KeyContent(x, x));
at 22 Sep 2021
eliawesome
Answers
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK