<%@ Page Language=http://www.mamicode.com/"C#" Inherits=http://www.mamicode.com/"System.Web.Mvc.ViewPage<dynamic>" %> <%@ Import Namespace=http://www.mamicode.com/"MvcApplication1.Models" %> <!DOCTYPE html> <html> <head runat=http://www.mamicode.com/"server"> <meta name=http://www.mamicode.com/"viewport" content=http://www.mamicode.com/"width=device-width" /> <title>Main</title> </head> <body> <table style=http://www.mamicode.com/"width: 100%; text-align: center;" cellspacing=http://www.mamicode.com/"0" cellpadding=http://www.mamicode.com/"0" border=http://www.mamicode.com/"1"> <tr style=http://www.mamicode.com/"background-color:navy;color:white;"> <td>序号</td> <td>用户名</td> <td>密码</td> <td>昵称</td> <td>性别</td> <td>生日</td> <td>民族</td> <td>班级</td> </tr> <% List<Users> ulist = new UsersData().Select(); foreach (Users u in ulist) { %> <tr> <td><%=u.ids %></td> <td><%=u.username %></td> <td><%=u.password %></td> <td><%=u.nickname %></td> <td><%=u.sex %></td> <td><%=u.birthday %></td> <td><%=u.nation %></td> <td><%=u.@class %></td> </tr> <%} %> </table> </body> </html>
View视图展示页面2、页面展示
3、属性扩展 性别、生日、民族、班级
代码:
<%@ Page Language=http://www.mamicode.com/"C#" Inherits=http://www.mamicode.com/"System.Web.Mvc.ViewPage<dynamic>" %> <%@ Import Namespace=http://www.mamicode.com/"MvcApplication1.Models" %> <!DOCTYPE html> <html> <head runat=http://www.mamicode.com/"server"> <meta name=http://www.mamicode.com/"viewport" content=http://www.mamicode.com/"width=device-width" /> <title>Main</title> </head> <body> <table style=http://www.mamicode.com/"width: 100%; text-align: center;" cellspacing=http://www.mamicode.com/"0" cellpadding=http://www.mamicode.com/"0" border=http://www.mamicode.com/"1"> <tr style=http://www.mamicode.com/"background-color:navy;color:white;"> <td>序号</td> <td>用户名</td> <td>密码</td> <td>昵称</td> <td>性别</td> <td>生日</td> <td>民族</td> <td>班级</td> </tr> <% List<Users> ulist = new UsersData().Select(); foreach (Users u in ulist) { %> <tr> <td><%=u.ids %></td> <td><%=u.username %></td> <td><%=u.password %></td> <td><%=u.nickname %></td> <td><%=Convert.ToBoolean(u.sex)?"男":"女" %></td> <td><%=Convert.ToDateTime(u.birthday).ToString("yyyy年MM月dd日") %></td> <td><%=u.Nation1.nationname %></td> <td><%=u.Class1.classname %></td> </tr> <%} %> </table> </body> </html>
View视图展示页面页面展示:
二、添加数据
1、设置<添加>按钮
代码:
<a href=http://www.mamicode.com/"/Home/Insert">添加</a>
2、Home控制器下Insert动作代码: