Reputation: 162
I just want to return a name through C# Enum GetName by passing int value from jquery.How can I do this?I've tried following code.
success: function (data) {
$("#CourseStatics").empty();
$.each(data, function (i) {
var optionhtml = '<tr><td>' + data[i].CourseCode + '</td> <td>'
+ data[i].CourseName + '</td><td>'
+ @Enum.GetName(typeof(AllEnums.Semester), data[i].SemesterId) + '</td><td>'
+ data[i].TeacherName + '</td></tr>';
$("#CourseStatics").append(optionhtml);
});
}
Upvotes: 0
Views: 383
Reputation: 4833
You can't pass your client-side variable to server-side code that way. But you can define object in your javascript code which you can use to covert int representation to name.
For example:
var map = {};
@foreach (var i in Enum.GetValues(typeof(AllEnums.Semester)))
{
@:map['id_@((int)i)'] = '@i';
}
and your code will look like:
success: function (data) {
$("#CourseStatics").empty();
$.each(data, function (i) {
var optionhtml = '<tr><td>' + data[i].CourseCode + '</td> <td>'
+ data[i].CourseName + '</td><td>'
+ map['id_' + data[i].SemesterId] + '</td><td>'
+ data[i].TeacherName + '</td></tr>';
$("#CourseStatics").append(optionhtml);
});
}
Upvotes: 1