//获取直属父级列表
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. 最常用的ES6特性

    遇到了要写出es6新特性的题目,所以查阅了资料来总结一下,点击查看原文. 进入正题,最常用的ES6特性有:let, const, class, extends, super, arrow functi ...

  2. 微信支付:curl出错,错误码:60

    如下是运行微信支付测试代码时出错代码: Fatal error: Uncaught exception ‘WxPayException‘ with message ‘curl出错,错误码:60‘ in ...

  3. build.gradle文件详解<转> 推荐

    apply plugin: 'com.android.application'//说明module的类型,com.android.application为程序,com.android.library为 ...

  4. angularJS中的Promise对象($q)的深入理解

    原文链接:a better way to learn AngularJS - promises AngularJS通过内置的$q服务提供Promise编程模式.通过将异步函数注册到promise对象, ...

  5. Centos7永久修改主机名

    最近在编写centos6.x的启动脚本,考虑到以后系统会升到7.x,故想让脚本兼容7.x,还是有一些和6版本不一样的地址,修改主机名比较常用,特此记录一下 1.命令行修改: hostnamectl s ...

  6. pure virtual function call

    2015-04-08 10:58:19 基类中定义了纯虚函数,派生类中将其实现. 如果在基类的构造函数或者析构函数中调用了改纯虚函数, 则会出现R6205 Error: pure virtual fu ...

  7. windows下的c语言和linux 下的c语言以及C标准库和系统API

    1.引出我们的问题? 标准c库都是一样的!大家想必都在windows下做过文件编程,在linux下也是一样的函数名,参数都一样.当时就有了疑问,因为我们非常清楚 其本质是不可能一样的,源于这是俩个操作 ...

  8. C#利用HttpWebRequest进行post请求的示例(HTTPS)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...

  9. 客户端实现蓝牙接收(C#)

    知识总结发布  (转载) 网上有关蓝牙接收的资料很多,使用起来也很简单,但是我觉得还是有必要把这些知识总结下来,蓝牙开发需要用到一个第三方的库InTheHand.Net.Personal.dll,感兴 ...

  10. jquery.validate使用 - 常用验证脚本

    一些常用的验证脚本 不会写js了,只能从网上找一些常用的验证脚本. // 手机号码验证jQuery.validator.addMethod("mobile", function(v ...