//UserInfoList.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户列表页面</title>
<meta charset="utf-8" />
<link href="css/tableStyle.css" rel="stylesheet" />
<script src="../jquery 3.3.1/jquery-3.3.1.js"></script>
<script>
$(function () {
$('.delCls').click(function () {
if (!confirm('确定要删除该记录吗?')) {
return false;
}
});
});
</script>
</head>
<body>
<a href="AddUserInfo.html">添加用户</a>
<table>
<tr>
<th>ID</th>
<th>名字</th>
<th>密码</th>
<th>详情</th>
<th>删除</th>
<th>编辑</th>
</tr>
$tbody
</table>
</body>
</html>
/******************************************************************************************************/
//UserInfoList.ashx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebProject.BLL;
using WebProject.Model;
using System.Text;
namespace WebProject.WebApp
{
/// <summary>
/// UserInfoList 的摘要说明
/// </summary>
public class UserInfoList : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
UserInfoBLL bll = new UserInfoBLL();
List<UserInfo> list = bll.GetAllUserInfo();
StringBuilder sb = new StringBuilder();
foreach(UserInfo user in list)
{
sb.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td><a href='UserInfoDetail.ashx?UserId={0}'>详情</a></td><td><a href='DeleteUserInfo.ashx?UserId={0}'>删除</a></td><td><a href='EditUserInfo.ashx?UserId={0}&&UserName={1}&&UserPwd={2}'>编辑<a></td></tr>",user.UserId,user.UserName,user.UserPwd);
}
string filePath = context.Request.MapPath("UserInfoList.html");
string fileContent = System.IO.File.ReadAllText(filePath);
fileContent = fileContent.Replace("$tbody", sb.ToString());
context.Response.Write(fileContent);
}
public bool IsReusable
{
get
{
return false;
}
}
}
}