ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Combobox shows ID instead of title when changing value of parent text control
Title:
B
I
{code}
?
Display ID instead of title in Ajax Radio List when setting text control as parent In View Html.Awe().TextBox("txtEmploymentCode").MaxLength(5) Html.Awe().AjaxRadioList("cboPesonList").Url(Url.Action("cboPerson", "Personely", new { Area = "HumanSystem" })).Parent("txtEmploymentCode", "EmploymentCode").Combobox(o => o.AutoSelectFirst()) In Controller public ActionResult cboPerson(string EmploymentCode) { var r = new Share.Response<List<Person>>("Person/AllPersons").Get(); if (!string.IsNullOrEmpty( EmploymentCode) ) r=r.Where(x=>x.EmploymentCode.Contains(EmploymentCode)).ToList(); var items = r.Select(o => new KeyContent(o.Id, o.FirstName + " " + o.LastName)); return Json(items,JsonRequestBehavior.AllowGet); } After changing the txtEmploymentCode value of AjaxRadioList instead of o.FirstName + " " + o.LastName a random number is set
Save Changes
Cancel
Arash
asked at 28 Jan 2024
Answers
B
I
{code}
?
The Combobox can have a combo value (not present in the options), I presume that before you change the value of the parent the Combobox already had a value, From the server you return a new list of items, and that list doesn't include the current value, this is why the combobox is showing its internal value instead of the content of a KeyContent from the options. Depending on your scenario you could: - use a DropdownList instead - clear the value of the combobox with js when the parent changes value - in the items list returned from the server include the current value also (you receive the current value as `v` parameter in the `cboPerson` Action) - you can also set the value from the Action that returns data, as shown here: https://demo.aspnetawesome.com/AjaxDropdownDemo#Set-value-from-get-items-call basically instead of `return Json(list)` you would return: return Json(new AweItems { Items = items, Value = value // value could be items.First().k });
Save Changes
Cancel
Omu
answered at 28 Jan 2024
Thank you very much
at 28 Jan 2024
Arash
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