BMills BMills - 4 months ago 7
Javascript Question

posting Url from dropdown without 'submit' button

In my view, I have dropdownlist:

@Html.DropDownList("InnerId", Model.GroupDropDownList, new { @class = "select_change" })


I would like to be able to submit the value when the user just clicks on the selection rather than selecting and using a submit button. I created the following script to try do this, but it won't accept the value of my variable
dropdownValue
as it just says
doesn't exist in current contect


$('.select_change').change(function () {
var dropdownValue = $('.select_change').val();
$.ajax({
type: "POST",
url:"@Url.Action("Group","EditMembers", new { @innerid= dropdownValue})"
})
})


Please note this question is cobbled together from various other similar questions and answers but I haven't been able to get any of the other similar questions on stack to work for me. Therefore please do not mark this question as duplicate as I really need some help with my specific example. Thanks.

Answer

This is a possible solution for it...

$('.select_change').change(function () {
var dropdownValue = $('.select_change').val();
var url = '@Url.Action("Group","EditMembers")';
$.ajax({
    type: "POST",
    url: url,
    data: {'innerid':dropdownValue }
    })
})