C#_dropdownlist_1
关于ASP.net MVC 中DropDownList绑定与提交数据
在做 ASP.net MVC项目中,数据绑定也是很关键的,现在以个人经验与大家交流下 ASP.net MVC 中DropDownList绑定与提交数据,由于数据查询较为简单就不列出来了,具体看核心代码部分吧。
数据表:

DropDownList绑定
public ActionResult ColumnManage() { ViewData["listchannel"] = new SelectList(b00.ListChannel(), "ChannelID", "ChannelName"); return View(); }
其中b00.ListChannel()是BLL层中的
View中
Code <h2>栏目管理</h2> <% SelectList categories = ViewData["listchannel"] as SelectList; %> <% using (Html.BeginForm()) { %> <div> <fieldset> <legend>添加栏目</legend> <p>栏目名称:<input type="text" id="columnname" style=" width:100px;"/></p> <p>上级目录:<select><option></option></select></p> <p>排 序:<input type="text" id="sort" style=" width:30px;"/></p> <p>频 道:<%=Html.DropDownList("listchannel", categories)%></p> <p><input type="submit" value="保存" /></p> </fieldset> </div> <% } %>
显示效果如下:

在提交时注意 DropDownList 还需要绑定一次
Code [AcceptVerbs(HttpVerbs.Post)] public ActionResult ColumnManage(string columnname,string sort) { try { ViewData["listchannel"] = new SelectList(b00.ListChannel(), "ChannelID", "ChannelName"); m00.ChannelID = int.Parse(Request.Form["listchannel"]); Response.Write(m00.ChannelID); return View(); } catch { return View(); } }
这样就可以提交获取DropDownList的 ID值了
C#_dropdownlist_1的更多相关文章
随机推荐
- 前端js框架收藏
1. AngularJS :AngularJS是为克服HTML在构建应用上的不足而设计的. 2. knockout 3. avalon :MVVM是前端究极的解决方案,因此之后我大多数时间都在折腾av ...
- Flash 导出图片和声音
命令文件 PolarBear_jsfl.zip Flash Professional 编辑器命令,用来导出 flash 库中的图片和声音 使用步骤: 1. 首先下载 PolarBear_jsfl.zi ...
- good bye 2015 B - New Year and Old Property
题意:统计在n,m之间的数的二进制表示形式只有一个零的数目. 位运算模拟+dfs #include<iostream> #include<string> #include< ...
- ADB Server Didn’t ACK ,failed to Start Daemon 解决方法
解决方法如下: 1.adb nodaemon server 查看不能执行的原因,输出: cannot bind ‘tcp:5037’ 2.定位到了是端口的问题!是5037端口被占用了! 3.netst ...
- ThinkPHP中SQL调试方法
$admin = D('Admin'); $info = $admin->field('`lastlogintime`,`lastloginip`')->where(array('user ...
- 使用Mono Cecil 动态获取运行时数据 (Atribute形式 进行注入 用于写Log) [此文报考 xxx is declared in another module and needs to be imported的解决方法]-摘自网络
目录 一:普通写法 二:注入定义 三:Weave函数 四:参数构造 五:业务编写 六:注入调用 7. 怎么调用别的程序集的方法示例 8. [is declared in another module ...
- how to learn device driver
making a linux usb driver http://www.kroah.com/linux/ http://matthias.vallentin.net/blog/2007/04/wri ...
- android中OnItemClickListener的参数解释
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) {} ...
- [iOS基础控件 - 3.3] 图片浏览器
需求: 1.显示当前图片序号/总图片数 2.显示图片 3.上一张图片.下一张图片转换 4.显示图片描述 A.数据的加载方式 1.逐个加载.处理 2.使用数组.字典分离数据和逻辑 3.延迟加载 ...
- JAVA生成PDF文件
生成PDF文件是主要应用的是ITEXT插件 import java.awt.Color; import java.io.File; import java.io.FileOutputStream; i ...