I have a piece of code which requests some list of objects using getjson method. Controller action method returns list of objects properly. Following code appends requested data in drop down list, but it is invisible/transparent data means it is appending my data but it is not visible i.e. it white/transparent. Here is the code:
<script>
$(document).ready(function () {
$('#b1').click(function () {
var userName = "Hello"
$.getJSON("/classes/getCourseList?username=" + userName, function (data1) {
var myOptions =
{
val1: data1.title
};
var $mySelect = $('#s1');
$.each(myOptions, function (val, text) {
$mySelect.append($('<option />',
{
value: val,
text: text
}));
});
});
});
});
</script>
Action method:
[AllowAnonymous]
public JsonResult getCourseList(string userName)
{
// Quiz q=new Quiz();
//q = _db.Quizzes.FirstOrDefault(x => x.QuizName.Equals(userName));
List<dummyCourses> list = new List<dummyCourses>();
foreach (Course c in db.Courses)
{
dummyCourses dc = new dummyCourses();
dc.title = c.title;
dc.creditHours = c.creditHours;
dc.instructor = c.instructor;
dc.code = c.code;
list.Add(dc);
}
return this.Json(list, JsonRequestBehavior.AllowGet);
}