//获取直属父级列表
var parents = _MemberEditDTOService.GetParents();
var parentsItems = parents.Result.Select(s => new SelectListItem()
{
Text = s.MemberName,
Value = ((int)s.Id).ToString()
}).ToList();
//parentsItems.First(t => t.Value.Equals("0")).Text = "--请选择--";
ViewBag.parentsSelectItems = parentsItems;

前端:

    @Html.DropDownList("MemberTypesSelectItems", ViewBag.MemberTypesSelectItems as SelectList, new { id = "memberTypes", Class = "form-control ", style = "display: inline-block;" })

或者

@Html.DropDownList("BusinessDepartment", new List<SelectListItem>
{
(new SelectListItem() {Text = "--请选择--", Value = "", Selected = true}),
(new SelectListItem() {Text = "业务部1", Value = "1", Selected = false}),
(new SelectListItem() {Text = "业务部2", Value = "0", Selected = false}),
}, new { @style = "width:99%;" }, new { id = "BusinessDepartment" })

或者

<select id="ddlUserType" class="form-control " style="width: 90px; display: inline-block;">
@foreach (var userType in ViewBag.UserType)
{
<option value="@userType.Value">@userType.Text</option>
}
</select>

Html.DropDownList的更多相关文章

  1. Asp.Net 将枚举类型(enum)绑定到ListControl(DropDownList)控件

    在开发过程中一些状态的表示使用到枚举类型,那么如何将枚举类型直接绑定到ListControl(DropDownList)是本次的主题,废话不多说了,直接代码: 首先看工具类代码: /// <su ...

  2. DropDownList 下拉框选择改变,促发事件和防全局刷新(记录)

    代码: <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:Script ...

  3. DropDownList实现可输入可选择

    1.js版本 <div style="z-index: 0; visibility: visible; clip: rect(0px 105px 80px 85px); positio ...

  4. js给DropdownList赋值

    ", "model": "APOLLO M/B1"}]; ; i < row.length; i++) { var addOption = do ...

  5. ASP.NET MVC 让@Html.DropDownList显示默认值

    在使用@Html.DropDownList的过程中,发现它的用法很局限,比如在加载的时候显示设定的默认项或者调整它的显示样式,在网上查了一些资料,终于把这个问题解决了. 一.View代码 @using ...

  6. GridView中实现DropDownList联动

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  7. "不能在 DropDownList 中选择多个项。"其解决办法及补充

    探讨C#.NET下DropDownList的一个有趣的bug及其解决办法 摘要: 本文就C#.Net 环境下Web开发中经常使用的DropDownList控件的SelectedIndex属性进行了详细 ...

  8. Asp.net mvc页面传值-- dropdownlist

    后台传值 List<ConfigParamInfo> paramList = configParamBLL.GetModelList(" and parentID=1" ...

  9. 怎么取得dropdownlist选中的ID值

    把数据库绑定在dropdownlist中,然后把选中的dropdownlist的项的ID值保存在另外的一个数据库中.怎么取得dropdownlist选中的ID值呢?? this.DropDownLis ...

  10. MVC5中后台提供Json,前台处理Json,绑定给Dropdownlist的例子

    MVC5中后台提供Json,前台处理Json,绑定给Dropdownlist的例子: 前端: 我们以前在前端定义了两个控件: <div class="row"> < ...

随机推荐

  1. placeholder修改字体和颜色

    textField.placeholder = @"username is in here!"; [textField setValue:[UIColor redColor] fo ...

  2. JSP页面和属性命名规范

     1.页面命名: 登陆 Login注册 Register用户 User创建 Create修改 Update删除 Delete查询 Selete控制器 Controller用户名 Username密码 ...

  3. IOS JSON

    //请求数据 dispatch_async(dispatch_get_global_queue(, ), ^{ _dataArray=[NSMutableArray array]; NSString ...

  4. GZDBHelperDemo 一

    1.新建Window窗体项目GZDBHelperDemo 2.从Nuget添加GZDBHelper引用 添加完成后会出现GZDBHelper的引用 3.添加数据库链接管理类 添加类库文件:Databa ...

  5. My first python script for work

    I write it yesterday to watch the NE process(rcpfd,cfgd) automatically, then i will write a window t ...

  6. 什么是js和js的基本语法

    时间:2016年12月15日 先讲讲基础语法: 大部分是来操作表单: js动态效果和数据交互(ajax?) js也有自己的API js大部分的DOM操作都是针对input的. 案例学习,对注册页面的简 ...

  7. crontab Job权限重要

    在撰写JOb时,需要将SH目录及文件设为777,方可正常执行~

  8. consul 模板配置内容的参数说明

    datacenters {{datacenters}} 数据中心 file {{file "/path/to/local/file"}} 读取本地文件的内容.如果不可读的话,会报错 ...

  9. RecyclerView 制作瀑布流图片

    这是瀑布流的效果图 RecyclerView(ListView的升级版) 加载图片用的是第三方图片加载框架 ------------------------------------- 在Xml中 &l ...

  10. django部署

    部署教程 阿里云django部署教程 注意备份Apache2的siteconf文件 细节 环境迁移 如果是修改了注意些requirement文件