這里需要幫助這是我的模特public class SelectOption{ public String Value { get; set; } public String Text { get; set; }}樣品方法public JsonResult GetJson(){ var list = new List<SelectOption> { new SelectOption { Value = "1", Text = "Aron" }, new SelectOption { Value = "2", Text = "Bob" }, new SelectOption { Value = "3", Text = "Charlie" }, new SelectOption { Value = "4", Text = "David" } }; return Json(list);}看法<script type="text/javascript"> $(document).ready(function() { $.getJSON("/Json/GetJson", null, function(data) { $("#MyList").addItems(data); }); }); $.fn.addItems = function(data) { return this.each(function() { var list = this; $.each(data, function(index, itemData) { var option = new Option(itemData.Text, itemData.Value); list.add(option); }); }); }; $("#MyList").change(function() { alert('you selected ' + $(this).val()); });</script>上面的代碼沒有任何錯(cuò)誤,只是在加載所有內(nèi)容時(shí),Select / Dropdownlist將具有4個(gè)空值,這意味著我可以單擊DDL并有4個(gè)值,但是對于所有這四個(gè)都是空字符串。有人知道為什么嗎?
- 1 回答
- 0 關(guān)注
- 134 瀏覽
添加回答
舉報(bào)
0/150
提交
取消