如何将选定值从下拉列表发送到MVC和Jquery / Ajax中的控制器 [英] How to send a selected value from a dropdown to a controller in MVC and Jquery/Ajax

查看:98
本文介绍了如何将选定值从下拉列表发送到MVC和Jquery / Ajax中的控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我需要使用jquery从下拉列表中获取所选值。然后我想将此选定值发送到我的控制器中的Action Result Method,可能使用Ajax调用。由于我是新手,我不太确定如何实现这个目标。

所以我的控制器中有一个这样的动作方法...





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 ...


       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


//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

推荐答案

#ModelResult)。val();
("#ModelResult").val();


.ajax({

type:' GET'
url:' ../../ VehiclesController / GetVehiclePart /' + vehicle,
dataType:' json'
成功:功能(数据){

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


#ModelResult)。val( );
console .log(vehicle); // 此处打印的值不确定如何将其发布到控制器


},
async: false

});
("#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


这篇关于如何将选定值从下拉列表发送到MVC和Jquery / Ajax中的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆