添加Action  EditUserInfo

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplicationStudy.Models;
namespace MvcApplicationStudy.Controllers
{
public class UserInfoController : Controller
{
//
// GET: /UserInfo/ public ActionResult Index()
{
TestEntities db = new TestEntities();
var userInfoList = db.UserInfo.Where<UserInfo>(c => true);
List<UserInfo> list = userInfoList.ToList();
// ViewBag.Model = list;
//return View();
return View(list);
}
//展示一条数据详细信息
public ActionResult ShowDetail(int id)
{
TestEntities db = new TestEntities();
UserInfo userInfo = db.UserInfo.Where<UserInfo>(u => u.ID == id).SingleOrDefault();
if (userInfo != null)
{
return View(userInfo);
}
else
{
return Content("参数错误");
}
}
public ActionResult EditUserInfo(int id)
{
TestEntities db = new TestEntities();
UserInfo userInfo = db.UserInfo.Where<UserInfo>(u => u.ID == id).FirstOrDefault();
if (userInfo != null)
return View(userInfo);
else
return Content("参数错误");
}
[HttpPost]
public ActionResult EditUserInfo(UserInfo userInfo)
{
TestEntities db = new TestEntities();
db.Entry<UserInfo>(userInfo).State = System.Data.EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
} }
}

  添加视图

@model MvcApplicationStudy.Models.UserInfo

@{
Layout = null;
} <!DOCTYPE html> <html>
<head>
<meta name="viewport" content="width=device-width" />
<title>EditUserInfo</title>
</head>
<body> @using (Html.BeginForm()) { @Html.HiddenFor(model =>model.ID) @Html.LabelFor(model => model.UserName)
<br /> @Html.EditorFor(model => model.UserName) <br /> @Html.LabelFor(model => model.UserPwd)
<br />
@Html.EditorFor(model => model.UserPwd)
<br /> @Html.LabelFor(model => model.RegTime)
<br />
@Html.EditorFor(model => model.RegTime)
<br /> <p>
<input type="submit" value="Save" />
</p> } <div>
@Html.ActionLink("Back to List", "Index")
</div>
</body>
</html>

  点击修改,运行结果

MVC入门——编辑页的更多相关文章

  1. MVC入门——删除页

    添加Action DeleteUserInfo using System; using System.Collections.Generic; using System.Linq; using Sys ...

  2. MVC入门——详细页

    添加Action ShowDetail using System; using System.Collections.Generic; using System.Linq; using System. ...

  3. MVC入门——列表页

    创建控制器UserInfoController using System; using System.Collections.Generic; using System.Linq; using Sys ...

  4. Java基础-SSM之Spring MVC入门篇

    Java基础-SSM之Spring MVC入门篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Spring MVC简介 1>.什么是Spring MVC 答:Sprin ...

  5. Asp.net MVC入门视频教程

    编程开发 > Asp.net视频教程 > Asp.net MVC入门视频教程 > 1.传统web处理方式和mvc处理方式 上传日期:2014-08-16 10:02:45  相关摘要 ...

  6. MVC入门教程

    MVC入门系列教程-视频版本,已入驻51CTO学院,文本+视频学效果更好哦.视频链接地址如下: 点我查看视频.另外,针对该系列教程博主提供有偿技术支持,群号:226090960,群内会针对该教程的问题 ...

  7. ASP.NET MVC 入门

    ASP.NET MVC 入门 (Learning ASP.NET MVC) 传统的WebForm发展到如今出现不少的缺陷, 比如为了解决Http的无状态WebForm模式使用了ViewsState来保 ...

  8. ASP.Net Core 2.2 MVC入门到基本使用系列 (一)

    本教程会对基本的.Net Core 进行一个大概的且不会太深入的讲解, 在您看完本系列之后, 能基本甚至熟练的使用.Net Core进行Web开发, 感受到.Net Core的魅力. 本教程知识点大体 ...

  9. ASP.Net Core 2.2 MVC入门到基本使用系列 (四)

    本教程会对基本的.Net Core 进行一个大概的且不会太深入的讲解, 在您看完本系列之后, 能基本甚至熟练的使用.Net Core进行Web开发, 感受到.Net Core的魅力. 本教程知识点大体 ...

随机推荐

  1. 加速和简化构建Docker(基于Google jib)

    赵安家 2019年02月11日阅读 1518 关注 加速和简化构建Docker(基于Google jib) 介绍 其实jib刚发布时就有关注,但是一直没有用于生产,原因有二 基于 spotify/do ...

  2. hdu 2857 点在直线上的投影+直线的交点

    Mirror and Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. poj 3068 "Shortest" pair of paths

    "Shortest" pair of paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1407 ...

  4. 百万级日活 App 的屏幕录制功能是如何实现的

    Android 从 4.0 开始就提供了手机录屏方法,但是需要 root 权限,比较麻烦不容易实现.但是从 5.0 开始,系统提供给了 App 录制屏幕的一系列方法,不需要 root 权限,只需要用户 ...

  5. bzoj 1196 公路修建问题

    bzoj 1196: [HNOI2006]公路修建问题 Description OI island是一个非常漂亮的岛屿,自开发以来,到这儿来旅游的人很多.然而,由于该岛屿刚刚开发不久,所以那里的交通情 ...

  6. Cryptography I 学习笔记 --- 流密码

    1. 对于一次性密码本(one time pad),没有唯密文攻击(cypher text only attack),也就是说如果攻击者只能拿到密文,他什么也做不了 2. 完美密码:密钥长度大于密文长 ...

  7. 牛客网 牛客小白月赛1 B.简单题2-控制输出格式

    B.简单题2   链接:https://www.nowcoder.com/acm/contest/85/B来源:牛客网 和A题一样,控制输出格式就可以. 代码: 1 #include<iostr ...

  8. win7阻止iis开机启动

    https://zhidao.baidu.com/question/111234812.html 1.在"开始/运行/" 输入"services.msc" 启动 ...

  9. scrapy 启动失败,scrapy startproject test 出错 'module' object has no attribute 'OP_NO_TLSv1_1

    你先看看 pip install scrapy需要的 pyopenssl  twisted  等和你安装的版本一样么  我的就是因为TWist 版本高于  需要的 用pip install twist ...

  10. Leetcode 232 Implement Queue using Stacks 和 231 Power of Two

    1. 232 Implement Queue using Stacks 1.1 问题描写叙述 使用栈模拟实现队列.模拟实现例如以下操作: push(x). 将元素x放入队尾. pop(). 移除队首元 ...