MVC dropdownlist使用
View中代码
@{
ViewBag.Title = "dropdownlist";
} <h2>dropdownlist</h2>
@using (Html.BeginForm())
{
<table>
<tr>
<td>test1</td>
<td>
<input type="radio" id="GenderM" name="Sex" value="男" />男
<input type="radio" id="GenderF" name="Sex" value="女" checked />女
<input type="text" id="" name="" value="">
</td>
</tr>
<tr>
<td>test2</td>
<td>
@Html.DropDownList("name", ViewBag.selList1 as IEnumerable<SelectListItem>)
</td>
</tr>
</table> <input type="submit" value="submit">
Control中代码
public ActionResult dropdownlist()
{
var q = from p in modeltest.Students select p;
List<student> droptest = q.ToList();
SelectList selList1 = new SelectList(droptest,"id","name");
ViewBag.selList1 = selList1.AsEnumerable(); //选择数据库数据绑定
return View();
} [HttpPost]
public ActionResult dropdownlist(string test="test")
{
var q = from p in modeltest.Students select p;
List<student> droptest = q.ToList();
ViewData["name"] = new SelectList(droptest,"id","name"); //重构dropdownlist
var name = modeltest.Students.Find(Convert.ToInt32(Request.Form["name"]));
formtest fm = new formtest { id = Convert.ToInt32(Request.Form[""]), value1 = Request.Form["sex"], value2 = name.name }; //通过view中的数据给model对象赋值
modeltest.formtest.Add(fm);
modeltest.SaveChanges();
return View(fm);
}
MVC dropdownlist使用的更多相关文章
- C# mvc DropDownList选中状态无效情况分析
情况: DropDownList控件使用List<SelectListItem>()设置下拉选项和默认值.当控件的Name和后台的ViewBag(或ViewData)的Key重复,会导致选 ...
- MVC DropDownList
最近发现一个 MVC中绑定前台DropDownList , 并且设置默认选中项的简单方法. 直接上代码 方案一 Action: ViewData["goodsTypeList"] ...
- MVC dropdownlist 后端设置select属性后前端依然不能默认选中的解决方法
-----------------------------------来自网上的解决方法--------------------------------------------- ASP.Net MV ...
- ASP.NET MVC Dropdownlist
本文介绍如何在网页里显示DropDownList. Step 1: 在Control里面添加方法 public ActionResult ShowDropDownList() { return Vie ...
- MVC dropdownlist 下拉框
List<SelectListItem> items = new List<SelectListItem>(); items.Add(new SelectListItem() ...
- MVC Dropdownlist数据绑定 默认值
@Html.DropDownList("Data", (SelectList)ViewBag.Data, new { @class = "form-control cho ...
- ASP.NET MVC DropdownList的使用
1:直接使用HTML代码写 <select name="year"> <option value="2011">2010</opt ...
- mvc DropDownList默认选项
DDDContext db = new DDDContext(); List<SelectListItem> selectlistDistrict = new List<Select ...
- Devexpress MVC DropDownList (持续更新))
@Html.DevExpress().DropDownEdit(settings => { settings.Name = "psBankCharge"; settings. ...
随机推荐
- libevent系列文章
Libevent 2 提供了 bufferevent 接口,简化了编程的难度,bufferevent 实际上是对底层事件核心的封装,因此学习 bufferevent 的实现是研究 Libevent 底 ...
- excel 数据导入数据表
环境: Windows server 2012 rm sql server 2012 excel 数据导入数据表 INSERT INTO [dbo].[AdminUser] SELECT [Adm ...
- make clean-kernel && make kernel
当在kernel下使用全编译指令后,回到主目录编译仍然有错,那么需要:在 kernel/include/config:删去该文件夹 make clean-kernel && make ...
- Android电源管理-休眠简要分析
一.开篇 1.Linux 描述的电源状态 - On(on) S0 - Working - Standb ...
- 第三方登录(1)OAuth(开放授权)简介及授权过程
3个角色:服务方,开发者,用户 a.用户在第在服务注册填写个人信息, b.服务方开放OAuth, c.开发者在服务方申请第3方登录,在程序中得到令牌后,经用户同意,可得到用户的个人信息. OAuth ...
- MVC列表页通过CheckBox进行批量选择删除
1.Html代码,将所有CheckBox包含于删除表单,并且所有列表项的CheckBox使用相同的Name,并且Value设置为数据项主键ID @using (Html.BeginForm(" ...
- HDFS的java操作方式
1.RPC 1.1 RPC (remote procedure call)远程过程调用. 远程过程指的是不是同一个进程. 1.2 RPC至少有两个过程.调用方(client),被调用方(server) ...
- 同步synchronized用法
今天在高人的指导下,对同步synchronized用法有了更高一层的理解,非常感谢他的无私奉献.在此把代码贴出来方便日后查阅. publicclass SfServlet { privatestati ...
- JAVA使用DES加密算法加密解密
程序中使用了.properties文件作为参数配置文档,好处是灵活配置各项参数 一旦对数据库的一些参数进行了配置,势必涉及数据库的IP,端口,用户名和密码 properties文件全是unicode编 ...
- window.location.href 放置在单独的JS文件中使用时问题
场景:假设当前浏览器地址栏的地址是:http://localhost:8888/SSHBoot/tourist/homeMainAction_signInUI.do, 现在我想在点击按钮时定位到“ht ...