**
主界面代码
**
@using System.Data;
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>List</title>
<link href="~/css/tableStyle.css" rel="stylesheet" />
</head>
<body>
<div>
<a href="~/Student/Add" onclick="return confirm('是否要添加用户信息?')">添加用户</a>
<table>
<thead>
<tr>
<td>删除</td>
<td>编辑</td>
<td>账号</td>
<td>密码</td>
<td>昵称</td>
<td>姓名</td>
<td>性别</td>
<td>电话</td>
</tr>
</thead>
<tbody>
@foreach (DataRow item in Model)
{
<tr>
<td><a href="~/Student/Delete?id=@(item["ID"])" onclick="return confirm('确定删除数据?')">删除</a></td>
<td><a href="~/Student/Edit?id=@(item["ID"])" onclick="return confirm('是否要进行修改?')">编辑</a></td>
<td>@item["ID"]</td>
<td>@item["Pwd"]</td>
<td>@item["NickName"]</td>
<td>@item["Name"]</td>
<td>@item["Sex"]</td>
<td>@item["Tel"]</td>
</tr>
}
</tbody>
</table>
</div>
</body>
</html>
**
控制器代码
**
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using UserModel;
namespace MVC框架.Controllers
{
public class StudentController : Controller
{
UserBLL.UserManager manager = new UserBLL.UserManager();
/// <summary>
/// 查看整张表
/// </summary>
/// <returns></returns>
public ActionResult List()
{
DataTable table = manager.GetUserList();
return View(table.Rows);
}
/// <summary>
/// 添加用户
/// </summary>
/// <returns></returns>
[HttpGet]
public ActionResult Add()
{
return View();
}
[HttpPost]
public ActionResult Add(UserModel.User user)
{
if (manager.AddUserInfo(user))
{
var script = String.Format("<script>alert('添加成功!');location.href='{0}'</script>", Url.Action("List"));
return Content(script, "text/html");
//return Redirect("~/Student/List");
}
else
{
var script = String.Format("<script>alert('添加失败!');location.href='{0}'</script>", Url.Action("List"));
return Conte