设为首页 加入收藏

TOP

MVC [Control与View交互]2
2015-07-20 17:33:36 来源: 作者: 【 】 浏览:3
Tags:MVC Control View 交互

<1>

控制器 Home

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;

namespace MvcApplication1.Controllers
{
    public class HomeController : Controller
    {
        private salesEntities db = new salesEntities();
        //
        // GET: /Home/

        public ActionResult Index()
        {

            //ViewData.Model = db.T_User.ToList();
            //return View();

            //以上两条代码相当于 

            return View(db.T_User.ToList()); //括号里的db.T_User.ToList()其实就是一个Model
        }
        public ActionResult Delete(int id)
        {
            //Single:返回序列中满足指定条件的唯一元素;如果有多个这样的元素存在,则会引发异常
            T_User t_user = db.T_User.Single(t => t.Id == id);  
            return View(t_user);
        }

    }
}

视图 Index (首页)

@*@model MvcApplication1.Models.T_User*@
@model IEnumerable
  
   

@{
    Layout = null;
}

html>



    
   
    
   Index


    
   
@foreach (var item in Model) { }
编号 姓名 年龄
@item.Id @item.Name @item.Age @Html.ActionLink("删除", "Delete", new { id=item.Id})


Delete (删除信息页)

@model MvcApplication1.Models.T_User

@{
    Layout = null;
}





    
  
    Delete


    

你确定要删除这条记录吗?

T_User
编号: @Model.Id
姓名: @Model.Name
年龄: @Model.Age
@using (Html.BeginForm()) {

| @Html.ActionLink("跳转到首页", "Index")

}
\ \

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇[ACM] POJ 3740 Easy Finding (D.. 下一篇LeetCode:signal_number题解

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·PostgreSQL 索引 - (2025-12-25 22:20:43)
·MySQL Node.js 连接 (2025-12-25 22:20:41)
·SQL 撤销索引、表以 (2025-12-25 22:20:38)
·Linux系统简介 (2025-12-25 21:55:25)
·Linux安装MySQL过程 (2025-12-25 21:55:22)