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; 
        }
    };
spr1x
  • 37
  • 8

1 Answers1

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?

Farzin Kanzi
  • 3,380
  • 2
  • 21
  • 23