zoukankan      html  css  js  c++  java
  • MVC 数据库增删改查(2) 视图

    (一) 表的主页的写法

    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %> <%@ Import Namespace="mvc_1_.Models" %> <!DOCTYPE html> <html> <head runat="server"> <meta name="viewport" content="width=device-width" /> <title>Index</title> <style> .tab { 100%; column-rule-color:#141313; column-rule-style:solid; text-align:center; } .tr1 { background-color:#fff; } .tr2 { background-color:#c3b7b7; } .tr { background-color:#f00; } </style> </head> <body> <div> <table class="tab" border="1"> <tr class="tr"> <td>学号</td> <td>姓名</td> <td>性别</td> <td>生日</td> <td>班级</td> <td></td> <td></td> </tr> <% List<student> list = ViewBag.date as List<student>; int i = 0; foreach (student s in list) { if(i%2==0) { %> <tr class="tr1"> <td><%=s.Sno %></td> <td><a href="index/jingzhunchaxun/<%=s.Sno %>"><%=s.Sname %></a></td> <td><%=s.Ssex %></td> <td><%=s.Sbirthday.Value.ToLongDateString().ToString() %></td> <td><%=s.Class %></td> <td> <a href="/index/A/<%=s.Sname %>">修改</a> </td> <td> <a onclick="return confirm('确认要删除<%=s.Sname.ToString() %>吗?')" href="index/Delete/<%=s.Sname %>">删除</a> </td> </tr> <%}else { %> <tr class="tr2"> <td><%=s.Sno %></td> <td><a href="index/jingzhunchaxun/<%=s.Sno %>"><%=s.Sname %></a></td> <td><%=s.Ssex %></td> <td><%=s.Sbirthday.Value.ToLongDateString().ToString() %></td> <td><%=s.Class %></td> <td> <a href="/index/A/<%=s.Sname %>">修改</a> </td> <td> <a onclick="return confirm('确认要删除<%=s.Sname.ToString() %>吗?')" href="index/Delete/<%=s.Sname %>">删除</a> </td> </tr> <%} %> <% i++; } %> </table> <a href="Index/Add">添加</a> </div> </body> </html>

    (二)修改的视图

    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
    <%@ Import Namespace="mvc_1_.Models"%>
          
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <meta name="viewport" content="width=device-width" />
        <title>A</title>
    </head>
    <body>
        <div>
              <form action="/index/Update" method="post">
                  <%
                      student data= ViewBag.Data as student;
                      if (data!=null)
        {
            
                       %>
             学号:<input type="text" name="code" value="<%=data.Sno %>"></br>
             姓名:<input type="text" readonly="readonly" name="name" value=<%=data.Sname %>></br>
             性别:<input type="text" name="sex" value=<%=data.Ssex %>></br>
             生日:<input type="text" name="shengri" value=<%=data.Sbirthday %>></br>  
             班级:<input type="text" name="banji" value=<%=data.Class %>>
                <input type="submit" value="更新">     
                  <%} %>
                  </form>
        </div>
    </body>
    </html>

    (三) 添加的视图

    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <meta name="viewport" content="width=device-width" />
        <title>Add</title>
    </head>
    <body>
        <div>
            <form action="/index/Insert" method="post">
             学号:<input type="text" name="code"></br>
             姓名:<input type="text" name="name"></br>
             性别:<input type="text" name="sex"></br>
             生日:<input type="text" name="shengri"></br>  
             班级:<input type="text" name="banji">
                <input type="submit" value="添加">          
    
            </form>
        </div>
    </body>
    </html>
  • 相关阅读:
    [SDOI2015]星际战争
    [SDOI2016]生成魔咒
    hdu3311
    [ZJOI2011]最小割
    P3331 [ZJOI2011]礼物(GIFT)
    [ZJOI2010]贪吃的老鼠
    状压dp-----三进制
    noip2016 天天爱跑步
    概率期望dp
    poj2186
  • 原文地址:https://www.cnblogs.com/w-wz/p/4624283.html
Copyright © 2011-2022 走看看