您的位置:首页 > 编程语言

收集的传递参数的代码片段,有 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);
}
}
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: