I would like to pass through the viewbag the name of the value field and the text field to put in my dropdownlist. This my code:
<script type="text/javascript">
var nameDDL = '@ViewBag.NameDDL';
var dropdownId = '#' + nameDDL;
var urlAction = '@ViewBag.UrlAction';
var keyField = '@ViewBag.KeyField';
var textField = '@ViewBag.TextField';
$(document).ready(
function () {
$(window).on("load",function () {
$.ajax({
type: 'GET',
data: {
'EveID': $("#ddlEveType").val()
//'EveID': '1'
},
url: urlAction,
contentType: "application/json",
success: function (data) {
console.log(data);
$.each(data, function (i, item) {
$(dropdownId).append($('<option>', {
This doesn't work ??????
value: item. keyField ,
text: item. textField
}));
});
}
});
});
});
</script>
How to pass this parameters dynamcally from viewbag ?