BiaoBai View部分:
@using ChengJiDaoRuChaXun.Dao; @{ Layout = null; List<BiaoBai> biaobai = ViewBag.biaobai; } <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>表白墙</title> <link href="~/Content/biaobai/index.css" rel="stylesheet" /> <script src="~/Content/biaobai/jquery-1.7.2.min.js"></script> <script src="~/Content/biaobai/index.js"></script> <script type="text/javascript"> $(function () { $(‘#shuaxin‘).click(function () { window.location = window.location; }) }); </script> <style type="text/css"> #shuaxin { display: block; width: 120px; height: 65px; cursor: pointer; background-image:url(‘/Content/images/chongpai.png‘); } #fabu { display: block; width: 120px; height: 65px; cursor: pointer; background-image: url(‘/Content/images/send.png‘); } </style> </head> <body> <div id=‘top‘> <span id=‘fabu‘ style="float:left" onclick="window.location.href = ‘/Function/FaBu‘"> </span> <span id="shuaxin" style="float:left"></span> </div> <div id=‘main‘> @if (biaobai != null) { Random r = new Random(); string c = "a"; foreach (BiaoBai item in biaobai) { c = "a" + (r.Next(5)+1);//循环随机数的产生,a1——a5 <dl class=‘paper @c‘>@*a1——a5*@ <dt> <span class=‘username‘>@item.Name</span> </dt> <dd class=‘content‘>@item.NeiRong</dd> <dd class=‘bottom‘> <span class=‘time‘>@item.ShiJian</span> <a href="" class=‘close‘></a> </dd> </dl> } } </div> <!--[if IE 6]> <script src="~/Content/biaobai/iepng.js"></script> <script type="text/javascript"> DD_belatedPNG.fix(‘#send,#close,.close‘); </script> <![endif]--> </body> </html>
BiaoBai Controller部分:
JiKaoChengJiEntities1 db; public FunctionController() { db = new Dao.JiKaoChengJiEntities1(); } protected override void Dispose(bool disposing) { if (disposing) { db.Dispose(); } base.Dispose(disposing); } // GET: Function public ActionResult Index() { return View(); } public ActionResult BiaoBai() { var q = from t in db.BiaoBai select t; var list = q.ToList(); ViewBag.biaobai = list; return View(); }
时间: 2024-10-05 10:20:07