更新时间:2023-01-07 08:13:51
您的Ajax调用将会
$("#linkId").on('click', function (event) {
var url = "GetList";
$.ajax({
data: {},
type: 'POST',
cache: false,
dataType: 'json',
url: url,
success: function (result) {
$("#dropDownId").empty();
$("#dropDownId").append('<option value="">Select One</option>');
$.each(result, function (i, item) {
$("#AddItemItemId").append('<option value="' + item.Value + '">' +
item.Text + '</option>');
// here we are adding option for States
});
},
error: function (ex) {
alertify.alert('We face some technical difficulties. Hello World');
}
});
event.preventDefault(event);
});
和后端C#代码会喜欢
[HttpPost]
public JsonResult GetList()
{
var itemlist = _itemManager.GetItems();
var itemList = itemlist.Select(item => new SelectListItem { Text = item.ItemName+" - "+item.PowerName, Value = Convert.ToString(item.Id) }).ToList();
return Json(new SelectList(itemList, "Value", "Text"));
}
希望这会对您有所帮助.编码愉快
Hope this will help you. Happy coding