【发布时间】:2021-10-27 02:13:34
【问题描述】:
我正在使用 API 获取数据并将其分配给 VIEW BAG,但在运行时它显示错误。
List<DevInfo> DevList = await RestApi.Instance.GetAllDevAsync();
var nameT = DevList.Select(a=>a.Name).ToList();
ViewBag.datasourceDevList = nameT;
在脚本中。
var nameList = <%= new JavaScriptSerializer().Serialize("@ViewBag.datasourceDevList") %>;
我要生成下拉列表。
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);
}
【问题讨论】:
标签: javascript jquery .net-core model-view-controller