简体   繁体   English

在Asp.Net MVC中使用jQuery Ajax绑定基于另一个ListBox选择的ListBox

[英]Bind ListBox Baed On Another ListBox Selection using jQuery Ajax in Asp.Net MVC

i have a database structure like this; 我有这样的数据库结构; 在此处输入图片说明

And in my view, i have shown them like this; 在我看来,我已经像这样向他们展示了; 在此处输入图片说明

Now, what i want is, if someone select category, i should call ajax request and send to the controller and then return back the related ie subcategories (the categoryId that is passed in) and display them in another listbox. 现在,我想要的是,如果有人选择了类别,我应该调用ajax请求并发送给控制器,然后返回相关的ie子类别(传入的categoryId)并在另一个列表框中显示它们。
Note: it is my requirement. 注意:这是我的要求。 I don't need to use dropdownlist. 我不需要使用下拉列表。 And i need to do this using ajax call. 我需要使用ajax调用来执行此操作。 Alittle descriptive answer would be much appreciable 小小的描述性答案将非常可观

General flow 1. Get change event 2. Call the controller - i used razor example 3. Get Data 4. Use the Data 常规流程1.获取更改事件2.调用控制器-我使用剃刀示例3.获取数据4.使用数据

$("#category").bind('change', function () {                  
                    if ($('#category').val().length != 0) {
                        //Send Value
                         $.ajax({                       
                        url: '@Url.Action("Action", "Controller")',
                        type: 'POST',
                        data: { category: $('#category').val()},   
            sucess : function(data) {
                //add the data to your sub category
            }                    
                        }),                           
                });

Note : Just a sample code you need to change to work with your requirment as Brian mentioned please also post the code that you have already completed. 注意:正如Brian提到的那样,您只需更改一个示例代码即可满足您的要求,请同时发布已经完成的代码。

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM