Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在MVC中,如何将dropdownlist的值传递给事件onchange?_Javascript_Jquery_Model View Controller_Onchange_Html.dropdownlistfor - Fatal编程技术网

Javascript 在MVC中,如何将dropdownlist的值传递给事件onchange?

Javascript 在MVC中,如何将dropdownlist的值传递给事件onchange?,javascript,jquery,model-view-controller,onchange,html.dropdownlistfor,Javascript,Jquery,Model View Controller,Onchange,Html.dropdownlistfor,我尝试使用MVC,但我不知道如何将dropdownlist的值传递给EventOnChange @Html.DropDownList("cblist_id", (IEnumerable<SelectListItem>)ViewBag.listproduct, new { size = 5, @class = "form-control", onchange = "GetProduct(" + this.value + ", 123)" }) 我得到这个错误的样本 Compiler

我尝试使用MVC,但我不知道如何将dropdownlist的值传递给EventOnChange

@Html.DropDownList("cblist_id", (IEnumerable<SelectListItem>)ViewBag.listproduct, new { size = 5, @class = "form-control", onchange = "GetProduct(" + this.value + ", 123)" })
我得到这个错误的样本

Compiler Error Message: CS1061: 'ASP._Page_Areas_Users_Views_Permit_GrandPermit_cshtml' does not contain a definition for 'value' and no extension method 'value' accepting a first argument of type 'ASP._Page_Areas_Users_Views_Permit_GrandPermit_cshtml' could be found (are you missing a using directive or an assembly reference?)

因此,我认为当我尝试获取dropdownlist的值时会出现问题。

这里的
this.value
指的是服务器端C#的上下文,您需要在JavaScript
onchange=“GetProduct(this,123)”上绑定下拉列表的
this

和其他直接传递值的方法,就像这样

@Html.DropDownList("cblist_id", (IEnumerable<SelectListItem>)ViewBag.listproduct, new { size = 5, @class = "form-control", onchange = "GetProduct(this.value, 123)" })


function GetProduct(selectedValue, number){

}
@Html.DropDownList(“cblist_id”,(IEnumerable)ViewBag.listproduct,新的{size=5,@class=“form control”,onchange=“GetProduct(this.value,123)”)
函数GetProduct(selectedValue、number){
}
我知道了。我使用
$(drp).val()
。非常感谢。
@Html.DropDownList("cblist_id", (IEnumerable<SelectListItem>)ViewBag.listproduct, new { size = 5, @class = "form-control", onchange = "GetProduct(this, 123)" })
function GetProduct(drp, number){
     $(drp).val() 
     //  or
     drp.value
}
@Html.DropDownList("cblist_id", (IEnumerable<SelectListItem>)ViewBag.listproduct, new { size = 5, @class = "form-control", onchange = "GetProduct(this.value, 123)" })


function GetProduct(selectedValue, number){

}