ASP.NET MVC企业级程序设计(增删,页面水平排列,字符串拼接,非空,添加框内默认提示)

目录

题目:

实现过程

控制器代码

DAL

BLL

Index

Deile


题目:

实现过程

控制器代码

cs 复制代码
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()
        {
            ViewBag.Show = BLL.PropertyInfoManager.Show();
            return View();
        }
        [HttpPost]
        public ActionResult Index(string userName, string phone, string area)
        {
            PropertyInfo model = new PropertyInfo();
            model.userName = userName;
            model.phone = phone;
         
            model.idCard ="aewf4we5f6w4ef65aw46ef";
            model.area = decimal.Parse(area);
            BLL.PropertyInfoManager.Add(model);

            return RedirectToAction("Index");
        }
        public ActionResult Delect(int id)
        {
            BLL.PropertyInfoManager.Delect(id);
            return RedirectToAction("Index"); 
            
            }
    }
}

DAL

cs 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcApplication1.Models;
namespace MvcApplication1.DAL
{
    public class PropertyInfoServices
    {
        public static List<PropertyInfo> Show() {
            PropertyDBEntities db = new PropertyDBEntities();
            return db.PropertyInfoes.ToList();
        }
        public static PropertyInfo FindModel(int id)
        {
            PropertyDBEntities db = new PropertyDBEntities();
            return db.PropertyInfoes.SingleOrDefault(x => x.Id == id);
        }
        public static bool Delect(int id)
        {
          PropertyInfo model=  FindModel(id);
            PropertyDBEntities db = new PropertyDBEntities();
            db.Entry(model).State = System.Data.EntityState.Deleted;
            return db.SaveChanges() > 0;
        }
        public static bool Add(PropertyInfo model) {
            PropertyDBEntities db = new PropertyDBEntities();
            db.Entry(model).State = System.Data.EntityState.Added;
           
            return db.SaveChanges() > 0;
        }
    }
}

BLL

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

namespace MvcApplication1.BLL
{
    public class PropertyInfoManager
    {
        
            public static List<PropertyInfo> Show()
            {
                return DAL.PropertyInfoServices.Show();
            }
           
            public static bool Delect(int id)
            {
                return DAL.PropertyInfoServices.Delect(id);
            }
            public static bool Add(PropertyInfo model)
            {
                return DAL.PropertyInfoServices.Add(model);
            }
        
    }
}

Index

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

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <div>
        <form method="post" action="/Home/Index" >

        
        <label>用户名:</label><br />
            <input type="text" placeholder="请输入用户名" name="userName" required/><br />
             <label>手机号:</label><br />
            <input type="text" placeholder="请输入手机号" name="phone" required/><br />
             <label>住房面积(含公摊):</label><br />
            <input type="text" placeholder="请输入住房面积" name="area" required/><br />
            <input type="submit" value="添加用户数据"/>
            </form>
        <table border="1" style=" position:absolute;top:5%;right:70%">
            <tr>
                <th>编号</th>
            <th>用户名</th>
            <th>手机号</th>
            <th>物业卡</th>
            <th>住房面积(含公摊)</th>
            <th>操作</th>
            </tr>
            @foreach (var item in @ViewBag.Show as List<MvcApplication1.Models.PropertyInfo>)
            {
                <tr>
                    <td>@item.Id</td>
                     <td>@item.userName</td>
                     <td>@item.phone</td>
                     <td>@item.idCard</td>
                     <td>@item.area (m²)</td>
                     <td>@Html.ActionLink("删除", "Delect", new { id = @item.Id }, new {onclick="return confirm('确定删除吗?')" })</td>
                </tr>
            }
        </table>
    </div>
</body>
</html>
相关推荐
红尘散仙2 小时前
我把终端小说阅读器接上了 AI Agent:TRNovel 现在能用 skill 生成书源了
人工智能·后端·rust
卷毛的技术笔记4 小时前
告别硬编码!Spring AI Alibaba 实现 AI Agent 智能工具调用(Tool Calling)
java·人工智能·后端·python·spring·ai编程
会编程的土豆4 小时前
Go 语言反射(Reflection)详解
开发语言·后端·golang
喵个咪4 小时前
GoWind Toolkit Go后端代码生成 完整全流程实战
后端·go·orm
basketball6165 小时前
Go 语言从入门到进阶:4. 数组和MAP使用方法总结
开发语言·后端·golang
qq_2518364575 小时前
SpringBoot+Vue 共享电池柜管理系统 完整实现 前后端分离项目实战 完整代码
vue.js·spring boot·后端
zhangxingchao5 小时前
AI 大模型核心六:量化、Workflow 与 Agent、多轮 RAG
前端·人工智能·后端
IT_陈寒6 小时前
Vite打包时遇到的坑,原来问题出在这里
前端·人工智能·后端
ayqy贾杰7 小时前
基层管理的三板斧,在AI时代行不通了
前端·后端·团队管理
Apifox7 小时前
Apifox 5 月更新|Postman 导入优化、Runner 支持非 root 运行、请求代码自动带鉴权
前端·后端·安全