收集的传递参数的代码片段,有 droplist , actionresult , button 的 链接等

████████████████████████████████████████████████████████████████████████████████████████████████████████
████████████████████████████████████████████████████████████████████████████████████████████████████████
███████████████████████████████  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);
        }
    }
}

  

转载于:https://www.cnblogs.com/zhbj/archive/2013/03/24/2978666.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值