ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
How to bind combobox to data using viewbag
Title:
B
I
{code}
?
I need to bind dropdown to data using viewbag instead of setting `url` which does ajax request . Is that possible? I need to populate data from sql table to dropdown using viewbag, Data consist list of two properties Id, DisplayText
Save Changes
Cancel
Baresha Shaik
asked at 20 Dec 2021
depends what do you mena by "bind", bind the value to viewmodel property
at 20 Dec 2021
Omu
I need to populate data in sql table to dropdown using viewbag, Data consist list of two properties Id, DisplayText
at 20 Dec 2021
Baresha Shaik
Answers
B
I
{code}
?
You could use the DataFunc to set data on the client as shown here: https://demo.aspnetawesome.com/AjaxRadioListDemo#Client-data in your case the client func will use the data that was received (rendered) from the ViewBag/ViewData, example: controller: ViewData["items"] = Db.Meals.Where(o => categories.Contains(o.Category.Id)) .Select(o => new KeyContent(o.Id, o.Name)) view: <script> function getData() { return @Html.Raw(DemoUtils.Encode(ViewData["items"])); } </script> @(Html.Awe().AjaxRadioList("combo1") .Combobox() .DataFunc("getData"))
Save Changes
Cancel
Omu
answered at 20 Dec 2021
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