0

I have three dropdowns - Name, Specialization and Year of Study. A name is linked to only one specialization and year of study. When I select a Name, I want the other two dropdowns to autocomplete themselves from the database acording to what Name I selected. This is my ajax code so far. What am I doing wrong?

$("#name").on('change', function () {
        GetStudentInfo();
    });

function GetStudentInfo() {
    var studId = $("#student").val();
     if (studId) {   
            $.ajax({
                url: '@Url.Action("GetStudentInfo", "StudentSituations")',
                type: 'GET',
                dataType: 'html',
                data: { studId: studId },
                success: function (data) {
                    $('#specialization').html(data);
                    $('#yearOfStudy').html(data);
                }
            });
            return false; 
        }
    };
1
  • 1
    What is your question? What is not working? Commented Mar 3, 2018 at 22:37

1 Answer 1

1

Your problem is here: url: '@Url.Action("GetStudentInfo", "StudentSituations")'. For ajax url you need to write a simple string. You need to pares your url by Razor view and replace the real value as the ajax url. You can see this post for better understanding:

Ajax call Into MVC Controller- Url Issue

And also I don't know what is '#student'? Are you sure this line:

var studId = $("#student").val();

works truly?

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Your answer was really helpful :)

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.