如何使用ajax从ASP.NET MVC中的数据库填充dropdownlist [英] How to populate dropdownlist from database in ASP.NET MVC using ajax

查看:57
本文介绍了如何使用ajax从ASP.NET MVC中的数据库填充dropdownlist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的mvc应用程序中有一个下拉列表,当页面加载时加载,但我不想这样做而是我想点击下拉列表并加载整个数据是否可以吗?



我尝试过:



< script>

$(#countrySelect )。change($(document).ready(function(){

debugger;

$ .get('Home / countrySelectList',function(data){

console.log(数据)

$ .each(数据,函数(索引,值){

$('< option>' ).val(value)。text(value).appendTo(#countrySelect);

});

});

});

< / script>

i have a dropdownlist in my mvc application which is loaded when the page load but i dont wantto do that instead i want to click the dropdown and load entire data is it possoble?

What I have tried:

<script>
$("#countrySelect").change($(document).ready(function () {
debugger;
$.get('Home/countrySelectList', function(data) {
console.log(data)
$.each(data, function(index, value) {
$('<option>').val(value).text(value).appendTo("#countrySelect");
});
});
}));
</script>

推荐答案

(#countrySelect)。change(
("#countrySelect").change(


(document).ready(function(){

debugger;
(document).ready(function () {
debugger;


.get('H ome / countrySelectList',function(data){

console.log(data)
.get('Home/countrySelectList', function(data) {
console.log(data)


这篇关于如何使用ajax从ASP.NET MVC中的数据库填充dropdownlist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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