使用三层架构、工厂模式以及MVC实现数据库的增删改查

**

主界面代码

**

@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
  • 4
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值