添加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. uva 103 Stacking Boxes(最长上升子序列)

    Description    Stacking Boxes  Background Some concepts in Mathematics and Computer Science are simp ...

  2. net5:动态修改内存中的站点地图节点

    原文发布时间为:2008-07-29 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...

  3. 转 Python执行系统命令的方法

    传送门 Python执行系统命令的方法 http://www.linux-field.com/?p=15 Python中执行系统命令常见方法有两种: 两者均需 import os (1) os.sys ...

  4. 快充 IC BQ25896 的 input current monitor

    BQ25896 沒有顯示 input current 的 register, 但可以讀 ILIM pin 的 電壓 做計算求出 input current.

  5. XSD(XML Schema Definition)学习笔记

    今天学习了XSD相关的知识,为了以后查找的方便,写一些笔记. 一.什么是XSD? 1.XSD全称:XML Schema Definition.XML Schema 的作用是定义 XML 文档的合法构建 ...

  6. 如何在官网上下载Linux版本的MySQL安装包

    如何在官网上下载Linux版本的MySQL安装包 参考百度经验,<如何在官网上下载Linux版本的MySQL安装包> 原文链接:https://jingyan.baidu.com/arti ...

  7. poj 3614(网络流)

    Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6672   Accepted: 2348 Descrip ...

  8. UVA - 10615 Rooks

    建一下模,把行和列看成二分图的点,把车看成是二分图中的边,这样就变成了上一个博客的问题. 我们每次新加一条边,就把它加入一条 这条边两端点最小没有出现的颜色  交替出现的路径中去. #include& ...

  9. Ubuntu 16.04下使用Wine安装文件内容搜索工具Search and Replace

    说明: 1.使用的Wine版本是深度出品(Deepin),已经精简了很多没用的配置,使启动能非常快,占用资源小. 2.关于没有.wine文件夹的解决方法:在命令行上运行winecfg: 下载: (链接 ...

  10. Android 源码编译记录

    问题1:Can't locate Switch.pm in @INC (you may need to install the Switch module) (@INC contains: /etc/ ...