如何根据db中的数据选择DropDownList中的项目? [英] How do I.select item in the DropDownList based on the data in the db?
本文介绍了如何根据db中的数据选择DropDownList中的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对不起,我是MVC新手..
我想在数据字段中设置我的下拉列表中的项目,如果它不为空。
我唯一的选择是做那个jquery还是旧的javascript?我希望DropDownList有一个重载来将项目设置为所选项目。
最好/最简单的方法是什么?
谢谢。
Sorry, I'm a MVC newbie..
I want to set an item in my dropdownlist from the data field if it is not null .
Are my only choices to do that jquery or old javascript? I was hoping that DropDownList had an overload to set an item as the selected item.
What is the best/easiest way to do that?
thank you.
@ Html.LabelFor(model => model.InstructorID,htmlAttributes:new {@class =control-label col-md-2})
@Html.LabelFor(model => model.InstructorID, htmlAttributes: new { @class = "control-label col-md-2" })
@ Html.DropDownList(InstructorID,[Select])
@Html.DropDownList("InstructorID", "[Select]")
推荐答案
检查出来:
1. 在编辑或更新视图中填充DropDownList中选定值的三种方法 - MVC [ ^ ]
2. 如何从模型中设置ASP.NET MVC DropDownList的默认值 [ ^ ]
Check thes out:
1. Three ways to populate selected value in DropDownList on Edit or Update views - MVC[^]
2. How to set default value for ASP.NET MVC DropDownList from model[^]
这篇关于如何根据db中的数据选择DropDownList中的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文