【ASP.NET MVC】使用动软(五)(13)

一、问题

前文完成的用户登录后的首页如下:

后续账单管理、人员管理等功能页面都有相同的头部,左边和下边,唯一不同的右边内容部分,所以要解决重复设计的问题。

二、解决方法------使用布局页

在Views上右键添加新建项,选择布局页,名称可改:

拷贝相同的头部、左边、下边的HTML到布局页,需要加载的地方用RenderBody

在index页面中测试

修改index页面

登录后,跳转到index

PS:图片和时间不正常的是路径的问题,如修改布局页的js路径解决时间问题

修改图片路径:

三、账单管理 页面的实现

首先 ,修改布局页中各项链接跳转

原来是静态页面方式,现改成"控制器+Action"

静态:

动态

以账单管理为例,用布局页实现功能:

在Home控制器中添加Action

复制代码
       [IsLogin]
        public ActionResult billList()
        {
            Maticsoft.BLL.bill bll = new Maticsoft.BLL.bill();
            List<Maticsoft.Model.bill> list = bll.GetModelList("");
            ViewBag.list = list;
            return View();
        }

IsLogin 见前文,取出数据表中所有账单信息,放入ViewBag。

右键该Action添加视图:

复制代码
@{
    Layout = "~/Views/_LayoutPage1.cshtml";
    List<Maticsoft.Model.bill> list = ViewBag.list;
}

<body>
     <div class="location">
                <strong>你现在所在的位置是:</strong>
                <span>账单管理页面</span>
            </div>
            <div class="search">
                <span>商品名称:</span>
                <input type="text" placeholder="请输入商品的名称"/>                
                <span>供应商:</span>
                <select name="tigong" >
                    <option value="">--请选择--</option>
                    <option value="">北京市粮油总公司</option>
                    <option value="">邯郸市五得利面粉厂</option>
                </select>
                <span>是否付款:</span>
                <select name="fukuan">
                    <option value="">--请选择--</option>
                    <option value="">已付款</option>
                    <option value="">未付款</option>
                </select>

                <input type="button" value="查询"/>
                <a href="billAdd.html">添加订单</a>
            </div>
            <!--账单表格 样式和供应商公用-->
            <table class="providerTable" cellpadding="0" cellspacing="0">
                <tr class="firstTr">
                    <th width="10%">账单编码</th>
                    <th width="20%">商品名称</th>
                    <th width="10%">供应商</th>
                    <th width="10%">账单金额</th>
                    <th width="10%">是否付款</th>
                    <th width="10%">创建时间</th>
                    <th width="30%">操作</th>
                </tr>
                @foreach (Maticsoft.Model.bill item in list)
                {
                    <tr>
                    <td>@item.id</td>
                    <td>@item.billName</td>
                    <td>@item.supplierid</td>
                    <td>@item.money</td>
                    <td>@item.zhifu</td>
                    <td>@DateTime.Now.ToString()</td>
                    <td>
                        <a href="billView.html"><img src="~/img/read.png" alt="查看" title="查看"/></a>
                        <a href="billUpdate.html"><img src="~/img/xiugai.png" alt="修改" title="修改"/></a>
                        <a href="#" class="removeBill"><img src="~/img/schu.png" alt="删除" title="删除"/></a>
                    </td>
                   </tr>
                }              
            </table>
</body>

使用布局页,解决重复页面代码问题,根据ViewBag动态生成页面内容:

PS:基于超市模板WEB项目的相关资料可以联系作者获取(740803366 易老师)

相关推荐
codeGoogle7 小时前
自研 IM 还是选择第三方 SDK?企业开发者应该如何权衡?
前端·后端·程序员
DLYSB_9 小时前
API 网关流量洪峰与突发 CC 攻击:我用 Go 写了个“现场物理防御哨兵”,把故障响应压缩到秒级
开发语言·后端·golang·报警灯
markinmarkin10 小时前
Spring 中Bean 的作用域有哪些?
java·后端·spring
全麦面包 time展天10 小时前
瀚海拾贝(一)HTTP协议/IIS 原理及ASP.NET运行机制浅析【图解】
网络协议·http·asp.net
橙子家11 小时前
使用方法 ToDictionary() 来优化查询时间复杂度:O(N*M) -> O(1*M)【C# 基础】
后端
IT_陈寒11 小时前
我又被JavaScript的隐式类型转换坑了
前端·人工智能·后端
用户83562907805111 小时前
Python Word 转 PDF 和 PDF 转 Word 指南
后端·python
用户83562907805111 小时前
如何使用 Python 加密和保护 Word 文档
后端·python
他们叫我秃子12 小时前
前端开发转 Go 全栈(五):终于遇到熟人了,Go 的闭包和高阶函数原来这么像 JavaScript
前端·后端·go
SomeB1oody12 小时前
【RustyML入门】2.6. 线性判别分析
开发语言·后端·机器学习·rust·教程