Click here to Skip to main content
15,922,894 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi All,

I need to get the selected value from a dropdown using jquery. Then i want to send this selected value to an Action Result Method in my controller possibly using Ajax call . As i am pretty new at this i'm not so sure on how i would achieve this.
so i have got an Action Method like this in my Controller ...


C#
       public ActionResult GetVehiclePart(string id)
       {    //i did like to send the selected value to this controller and filter data  like below
             var _partNumber = _catalogue.CatalogueData.FirstOrDefault(x => x.Partnumber         == id        && x.Veh_ID == selectedValue);
return PartialView("_Vehicle", _partNumber)
       }


And in my script file


JavaScript
//getting the value using jquery
  var vehicle = $("#ModelResult").val();
                            $.ajax({

                                type: 'GET',
                                url: '../../VehiclesController/GetVehiclePart/' + vehicle,
                                dataType: 'json',
                                success: function (data) {

                                    vehicle = $("#ModelResult").val();
                                    console.log(vehicle); // the value is printing here not sure how to post it to the controller


                                },
                                async: false

                            });



I may be doing something wrong here but if someone would help on how to achieve i would really appreciate it .. Thank you
Posted
Comments
Snesh Prajapati 4-Nov-15 7:26am    
Try by changing url like. url: '/VehiclesController/GetVehiclePart/' + vehicle and type as 'POST'
Thanks.

Try changing your ajax call with the following code,
JavaScript
//getting the value using jquery
var vehicle = $("#ModelResult").val();
    $.ajax({
    type: 'GET',
    url: '../../VehiclesController/GetVehiclePart?id=' + vehicle,
    dataType: 'json',
    success: function (data) {
        vehicle = $("#ModelResult").val();
        console.log(vehicle); 
    },
    async: true // make it true if you want to make an async call.
});


[Edit]
Added dataType twice :doh:

-KR
 
Share this answer
 
v2
Comments
1Future 5-Nov-15 9:50am    
this indeed to help me .. tank you
Krunal Rohit 5-Nov-15 10:00am    
Of course, it did. :)

-KR
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900