I am fetching the data using API and assign it to VIEW BAG but at run time it shows me an error.
List<DevInfo> DevList = await RestApi.Instance.GetAllDevAsync(); var nameT = DevList.Select(a=>a.Name).ToList(); ViewBag.datasourceDevList = nameT;
And in the script.
var nameList = <%= new JavaScriptSerializer().Serialize("@ViewBag.datasourceDevList") %>;
I want to generate the dropdown list.
if (nameList != '') { var tableHtml; $.each(JSON.parse(nameList), function (index, value) { //tableHtml += "<option value=" + value.Name + ">" + value.Name + "</option>"; console.log(value); }); /*$("#selectTrainer").html(tableHtml);*/ $("#selectTrainer").append(tableHtml); }