带有Razor的ASP.NET MVC4-通过从另一个下拉列表中选择的值来过滤下拉列表 [英] ASP.NET MVC4 with Razor - Filtering dropdownlist by value selected from another dropdownlist
问题描述
我必须通过从另一个下拉列表中选择的值来过滤下拉列表的选项.在我的数据库中,我有一张包含所有国家/地区的表格,以及一张包含世界所有城市的表格,并带有指向相应国家/地区的FK.
这是我的视图和页面的一部分:
还有我的控制器方法(页面的GET方法,所有国家/地区的加载以及一个国家/地区的所有城市的加载):(我删除了图片)
我必须处理第一个下拉列表的"onchange"事件,以修改第二个下拉列表的所有选项(在控制器中调用LoadCities方法并传递第一个下拉列表中所选项目的值),但我对此一无所知怎么做.
谢谢您的帮助!
UDPADE
感谢@Shyju提供您的建议,但仍然无法正常工作.我是一名学生,对这个主题我不太了解,结果如下: 您可以看到Content-Length为0,实际上响应面板为空. 为什么类型是xml?什么是"X-Requested-With"?我该如何解决?
使用javascript或jquery OnChange方法. 并传递第一个下拉ID,然后使用Ajax通过传递下拉ID来调用该方法.
I have to filter the options of a dropdownlist by value selected from another dropdown. In my database I have a table with all countries and a table with all cities of the world with a FK to the respective country.
Here is a part of my view and my page:
And my controller methods (the GET method of the page, the loading of all countries and the loading of all cities of a country): (I removed the image)
I have to handle the "onchange" event of the first dropdownlist to modify all the options of the second (calling the LoadCities method in my controller and passing the value of the selected item of first drop) but I have no idea about how to do it.
Thank you for your help!!
UDPADE
Thank @Shyju for your advices but it still does not working. I am a student and I don't know much about the topic, here are the results: You can see that the Content-Length is 0, in fact the response panel is empty. Why the type is xml? What is "X-Requested-With"? How can I fix it?
use javascript or jquery OnChange method. and pass the 1st dropdown Id and use ajax to call the method by passing dropdown Id.
这篇关于带有Razor的ASP.NET MVC4-通过从另一个下拉列表中选择的值来过滤下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!