我有一個下拉列表,其中包含一個從數據庫綁定的產品列表。我想加載選定的產品數據。這是我的代碼 @Html.DropDownListFor(model => model.ProductName, new SelectList(Model.ProductsList, "ProductID", "ProductName"), new { id = "Productslist", @class = "GreenDropDownListStyle", @datastyle = "dropdown", @onchange = "FillProduct()" })我曾使用 java 腳本代碼發送選擇的產品 ID 然后獲取它的數據<script type="text/javascript"> $(document).ready(function () { $("#Productslist").change(function () { debugger; var selectedIndex = $(this).val(); var divH = document.getElementById(selectedIndex); if (selectedIndex > 0) { $.ajax( { url: '/Inventory/ViewProduct', type: 'GET', data: { ProductID: selectedIndex }, contentType: 'application/json; charset=utf-8', success: function (data) { /// }, error: function () { alert("error"); } }); } else { divH.style.visibility = 'hidden'; // Hide } }); }); </script>此代碼發送所選索引的問題不是所選產品的問題,它還將 id 作為字符串發送,因此它永遠不會進入我的條件,以防萬一成功我應該寫什么
添加回答
舉報
0/150
提交
取消