0

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);
                        });
                    }

1 Answer 1

1

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);
                    });
                }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.