收集的传递参数的代码片段,有 droplist , actionresult , button 的 链接等
2013-03-24 15:48
363 查看
████████████████████████████████████████████████████████████████████████████████████████████████████████ ████████████████████████████████████████████████████████████████████████████████████████████████████████ ███████████████████████████████ index.cshtml 文件 ██████████████████████████████████████████████████ ████████████████████████████████████████████████████████████████████████████████████████████████████████ ████████████████████████████████████████████████████████████████████████████████████████████████████████ @model IEnumerable<MvcApp1.Models.dt_2_jiben> @{ ViewBag.Title = "媒体索引"; } <h2>媒体索引</h2> <p> @Html.ActionLink("创建新的记录", "Create") </p> @using (Html.BeginForm()) { <p> 民族:@Html.DropDownList("minz","All") 姓名:@Html.TextBox("xingm")<br /> <input type="submit" value="搜索" /> <a href="<%=Url.Action('Index','jiben')%>">返回</a> </p> } <table> <tr> <th> 序号 </th> <th> @Html.DisplayNameFor(model => model.罪犯编号) </th> <th> @Html.DisplayNameFor(model => model.日期) </th> <th> @Html.DisplayNameFor(model => model.姓名) </th> <th> @Html.DisplayNameFor(model => model.民族) </th> <th> @Html.DisplayNameFor(model =>model.家庭住址) </th> <th>操作</th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.ID ) </td> <td> @Html.DisplayFor(modelItem => item.罪犯编号) </td> <td> @Html.DisplayFor(modelItem => item.日期) </td> <td> @Html.DisplayFor(modelItem => item.姓名) </td> <td> @Html.DisplayFor(modelItem => item.民族) </td> <td> @Html.DisplayFor(modelItem=>item.家庭住址) </td> <td> @Html.ActionLink("编辑", "Edit", new { id=item.ID }) | @Html.ActionLink("查看", "Details", new { id=item.ID }) | @Html.ActionLink("删除", "Delete", new { id=item.ID }) </td> </tr> } </table> <div> @Html.ActionLink("返回", "Index") @using (Html.BeginForm( "index","jiben")) { <button id="but01" type="submit" style="width: 120px; height: 35px;">返回</button> } </div> ████████████████████████████████████████████████████████████████████████████████████████████████████████ ████████████████████████████████████████████████████████████████████████████████████████████████████████ ███████████████████████████████ jibencontroll.cs 文件 ██████████████████████████████████████████████████ ████████████████████████████████████████████████████████████████████████████████████████████████████████ ████████████████████████████████████████████████████████████████████████████████████████████████████████ using System; using System.Collections.Generic; using System.Data; using System.Data.Entity; using System.Linq; using System.Web; using System.Web.Mvc; using MvcApp1.Models; namespace MvcApp1.Controllers { public class jibenController : Controller { private dt_2_jibenContext db = new dt_2_jibenContext(); // // GET: /movie/ public ActionResult Index(string minz,string xingm) { // return View(db.dt_2_jiben.ToList() ); var genre = from t in db.dt_2_jiben orderby t.ID select t.民族; var GenreList = new List<string>(); GenreList.AddRange(genre.Distinct()); ViewBag.minz = new SelectList(GenreList); var movies = from t in db.dt_2_jiben select t; if (!string.IsNullOrEmpty(xingm)) { movies = movies.Where(m => m.姓名.Contains(xingm)); } if (string.IsNullOrEmpty(minz)) { return View(movies); } else { return View(movies.Where(m => m.民族 == minz)); } } // // GET: /movie/Details/5 public ActionResult Details(int id = 0) { dt_2_jiben dt_2_jiben = db.dt_2_jiben.Find(id); if (dt_2_jiben == null) { return HttpNotFound(); } return View(dt_2_jiben); } // // GET: /movie/Create public ActionResult Create() { return View(); } // // POST: /movie/Create [HttpPost] public ActionResult Create(dt_2_jiben dt_2_jiben) { if (ModelState.IsValid) { db.dt_2_jiben.Add(dt_2_jiben); db.SaveChanges(); return RedirectToAction("Index"); } return View(dt_2_jiben); } // // GET: /movie/Edit/5 public ActionResult Edit(int id = 0) { dt_2_jiben dt_2_jiben = db.dt_2_jiben.Find(id); if (dt_2_jiben == null) { return HttpNotFound(); } return View(dt_2_jiben); } // // POST: /movie/Edit/5 [HttpPost] public ActionResult Edit(dt_2_jiben dt_2_jiben) { if (ModelState.IsValid) { db.Entry(dt_2_jiben).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(dt_2_jiben); } // // GET: /movie/Delete/5 public ActionResult Delete(int id = 0) { dt_2_jiben dt_2_jiben = db.dt_2_jiben.Find(id); if (dt_2_jiben == null) { return HttpNotFound(); } return View(dt_2_jiben); } // // POST: /movie/Delete/5 [HttpPost, ActionName("Delete")] public ActionResult DeleteConfirmed(int id) { dt_2_jiben dt_2_jiben = db.dt_2_jiben.Find(id); db.dt_2_jiben.Remove(dt_2_jiben); db.SaveChanges(); return RedirectToAction("Index"); } protected override void Dispose(bool disposing) { db.Dispose(); base.Dispose(disposing); } } }
相关文章推荐
- C#和asp.net中链接数据库中参数的几种传递方法实例代码
- startActivityforResult传递List<Object>参数错误问题
- Strut2在Action-Result的配置文件内转到jsp页面时用URL传递参数
- C#和asp.net中链接数据库中参数的几种传递方法实例代码
- <a href 链接传递中文参数后台action接受乱码解决
- struts2的result为redirectAction时的参数传递
- 收集整理的工具代码片段链接
- ASP.NET MVC3如何用JQuery传递数组(集合)类型参数给JsonResult Action
- ASP.NET MVC3如何用JQuery传递数组(集合)类型参数给JsonResult Action
- Struts2+OGNL传递参数List,Map的一个小例子
- Com组件调用JS代码并传递多个参数个JS函数
- 转代码片段:MS CRM2011 获取某个实体的某个Picklist属性的所有值
- 关于在多个Action之间传递参数
- Jni 参数传递与操作——(C/C++ 代码与 java 代码的互相调用)
- struts 页面调用Action的指定方法并传递参数
- struts2 result传递参数问题
- Button点击事件绑定中如何传递带参数的方法
- struts2 redirect-action 传递参数问题
- struts的action 中向jsp中传递参数
- 【Struts】接收表单传递给Action的参数