ASP.NET MVC企业级程序设计 (EF+三层架构+MVP实现查询数据)

目录

效果图

实现过程

1创建数据库

2创建项目文件

3创建控制器,右键添加,控制器

[​编辑 注意这里要写Home​编辑](#编辑 注意这里要写Home编辑)

创建成功

数据模型创建过程之前作品有具体过程​编辑

4创建DAL

5创建BLL

6创建视图,右键添加视图

[​编辑 7HomeController.cs代码](#编辑 7HomeController.cs代码)

8Index.cshtml代码


效果图

实现过程

1创建数据库

2创建项目文件

3创建控制器,右键添加,控制器

注意这里要写Home
创建成功
数据模型创建过程之前作品有具体过程

4创建DAL

cs 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcApplication1.Models;
namespace MvcApplication1.DAL
{
    public class PersonDAL
    {
        public static List<Models.Users> Find(string name) {
            PersonDBEntities db = new PersonDBEntities();
            return db.Users.ToList().Where(x => x.Name.ToString().Contains(name)).ToList();

          
        
        }
    }
}

5创建BLL

cs 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MvcApplication1.BLL
{
    public class PersonBLL
    {
        public static List<Models.Users> Find(string name)
        {
            return DAL.PersonDAL.Find(name);



        }
    }
}

6创建视图,右键添加视图

7HomeController.cs代码

cpp 复制代码
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
    {
        //
        // GET: /Home/

        public ActionResult Index(string name)
        {
            if (name==null)
            {
                PersonDBEntities db = new PersonDBEntities();
                ViewData["users"] = db.Users.ToList();
            }
            else
            {
                ViewData["users"] = BLL.PersonBLL.Find(name);
            }
            ViewData["xianshi"] = name;
            return View();
        }

    }
}

8Index.cshtml代码

html 复制代码
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
   <form method="post" action="/Home/Index">
        <label>模糊查找姓名</label> 
       <input type="text" name="name" value="@ViewData["xianshi"]" />
       <input id="Submit1" type="submit"  value="查找"/>
   </form>
              


    <div>
        <table border="1">
            <tr>
                <th>ID</th>
                 <th>姓名</th>
                 <th>年龄</th>
            </tr>
            @{
                foreach (var item in ViewData["users"] as List<MvcApplication1.Models.Users>)
                {
                     <tr>
                <td>@item.ID</td>
                 
                 <td>@item.Name</td>
                         <td>@item.Age</td>
            </tr>
                }
                
                }
        </table>
    </div>
</body>
</html>
相关推荐
Csvn1 天前
Day 3:LIKE 与模式匹配 — 让查询学会"模糊搜索"
后端·sql
Hazenix1 天前
Go 指南:一篇文章速通 Golang
开发语言·后端·golang
灯澜忆梦1 天前
GO_复合类型---指针
开发语言·后端·golang
IT_陈寒1 天前
SpringBoot自动装配坑了我一天,原来问题出在这
前端·人工智能·后端
星栈1 天前
深度复盘:比 EventLoop 更隐蔽!Node 微任务堆积引发的线上接口雪崩事故
后端·node.js
名字还没想好☜1 天前
Go slice 的 append 陷阱:共享底层数组导致的数据串改
开发语言·后端·golang·go·slice
诸神缄默不语1 天前
FastAPI后端配置CORS中间件支持浏览器跨域访问
后端·fastapi
Fanta丶1 天前
14.Activiti7 网关 排他网关ExclusiveGateway、并行网关ParallelGateway
后端
明月_清风1 天前
robots.txt 完全指南:从入门到精通
后端·爬虫
jvmind_dev1 天前
Java GC 实战指南(番外篇):被忽视的隐形杀手 —— Class Unloading 如何拖垮 GC
java·后端