mvc 下拉列表 DropDownList 两种绑定方式
来源:互联网 发布:抢票软件 付费 编辑:程序博客网 时间:2024/05/10 05:16
前台
@Html.DropDownListFor(model=> model.lishudanweiid, ViewBag.DevNameList asIEnumerable<SelectListItem>, "请选择", new {@class = "form-control" })
后台
1绑定数据源 :ViewBag.DevNameList 红色部分要与前台一致
public void GetTielujuInfos()
{
List<Model.Sys_Station>seriesList = StationService.LoadEntities(u =>u.higherUpcode.Equals("A0000")).ToList(); ;
//1.2将YzSeriesEntity的数据封装到SelectList中,制定要生成下拉框选项的value和text属性
SelectList selList1 = newSelectList(seriesList, "UnitCode", "UnitName");
ViewBag.DevNameList = selList1;
}
Id和text 同时拿到
<input type="hidden"name="lishudanwei" id="lishudanwei" />
$("#lishudanwei").val($("#lishudanweiidoption:selected").text());
$("#text").val($("#id option:selected").text());
$("#id option:selected").val()
判断请选择
if("请选择" == $("#leixingid option:selected").text()) {
$.messager.alert('警告', '请选择类别!');
return;
}
另外一种下拉绑定适合多个共用
新增前台:
页面:<inputclass="easyui-combobox" id="leixingid"
name="leixingid"
data-options="
url:'/Zhiqinshilileixing/GetQicaileibie',
valueField:'id',
textField:'name',
panelHeight:'auto'
" required="true">
提交获取值: $("#leixingmingcheng").val($("#leixingid").combobox('getText'));
相同后台:
public ActionResult GetQicaileibie()
{
var data = ZhiqinshilileixingService.LoadEntities(u => true);
var d1 = from d in data
select new
{
d.id,
d.name
};
return Json(d1);
}
编辑
页面加载:
$('#leixingid').combobox({
url:'/Zhiqinshilileixing/GetQicaileibie',
valueField: 'id',
textField: 'name',
});
页面:<input id="leixingid" name="leixingid"value="@Model.leixingid" required="true" />
提交获取值: $("#leixingmingcheng").val($("#leixingid").combobox('getText'));
- mvc 下拉列表 DropDownList 两种绑定方式
- DropDownList(下拉列表框)绑定数据的方式
- 两种绑定DropDownList数据源的方式
- MVC 绑定下拉列表
- dropdownlist 下拉列表绑定再添加数据项
- Repeater中的下拉列表DropDownList绑定数据源
- 下拉框数据绑定两种方式
- 实现下拉列表的两种方式
- asp.net MVC几种绑定下拉列表的写法
- DropDownList 绑定数据库中的字段获取下拉列表值
- DropDownList 绑定数据库中的字段获取下拉列表值
- 可输入的下拉列表 支持dropdownlist的数据源绑定
- DropDownList 绑定数据库中的字段获取下拉列表值
- Yii 下拉列表-dropdownlist
- DropDownList 下拉列表显示
- ListBox绑定数据库两种方法 dropdownlist
- DropdownList绑定的两种方法
- DropDownList绑定数据的两种方法
- 动态规划之Help Jimmy
- 关于 Java 中 finally 语句块的深度辨析
- r.js结合gulp等于webpack(angular为例)
- html+css的基本知识总结(一)
- 云主机 环境搭配 交接文档
- mvc 下拉列表 DropDownList 两种绑定方式
- opencv(4)--cvCreateTrackbar一个有滚动条的播放器
- openswan和xl2tpd搭建VPN以及使用
- 利用二进制枚举
- Python 基础知识教程
- CXF对Interceptor拦截器的支持
- Spark Graphx 进行团伙的识别(community detection)
- ORACLE---自定义function语法
- Codeforces Gym 100623E Problem E. Enchanted Mirror