NET MVC中 DropDownList的BUG
2015-11-12 14:19
148 查看
最近小弟在.net mvc开发中发现DropDownList中的一个bug。下面阐述bug发生的情况
首先看Controller代码:
public ActionResult Index()
{
List<SelectListItem> country = new List<SelectListItem>();
country.Add(new SelectListItem() { Text = "中国", Value = "1", Selected = true });
country.Add(new SelectListItem() { Text = "美国", Value = "2" });
country.Add(new SelectListItem() { Text = "日本", Value = "3" });
ViewBag.country = country;
return View();
}
在看View层代码:
<div>
<span>国家</span>
@Html.DropDownList("country", ViewBag.country as List<SelectListItem>, "请选择")
</div>
在看结果:
正确结果应该是中国在选中状态。
那是什么原因产生的呢,为什么不在选中的状态呢,
如果两个名称不相同时,结果就正确了。
最近小弟在.net mvc开发中发现DropDownList中的一个bug。下面阐述bug发生的情况
首先看Controller代码:
public ActionResult Index()
{
List<SelectListItem> country = new List<SelectListItem>();
country.Add(new SelectListItem() { Text = "中国", Value = "1", Selected = true });
country.Add(new SelectListItem() { Text = "美国", Value = "2" });
country.Add(new SelectListItem() { Text = "日本", Value = "3" });
ViewBag.country = country;
return View();
}
在看View层代码:
<div>
<span>国家</span>
@Html.DropDownList("country", ViewBag.country as List<SelectListItem>, "请选择")
</div>
在看结果:
正确结果应该是中国在选中状态。
那是什么原因产生的呢,为什么不在选中的状态呢,
如果两个名称不相同时,结果就正确了。
相关文章推荐
- cpu有哪些架构
- Linux 下的定时任务实现 at 和 crontab
- CentOS 配置Tomcat及搭配Nginx
- popen,argc,argv, cprintf, snprintf,strcmp,write,read,strspn,strcspn,
- 常用web技术学习的视频网站
- squid代理
- 安装Tomcat
- Linux 系统挂载数据盘
- Lucene工具箱之OpenBitSet
- [Shell] 读取脚本路径
- Ubuntu下编译Openpilot
- 基于opencv的摄像头提取
- Tomcat7 开启CGI,并配置awstats日志监控
- 阿里巴巴rocketmq的运维指令
- LINUX 搭建sftp 服务器
- Xcode 真机测试 could not find developer disk image解决方法
- linux学习笔记(1):终端操作方法积累
- linux学习笔记(2):linux下的常用编辑器
- OPenCV相机标定函数
- Linux 网桥配置命令:brctl