一般删除网页数据和jquery下使用Ajax删除数据的区别

1. 一般删除网页数据

就是指用户在点击删除的时候,会跳转到DeleteUser.ashx一般处理程序中,并且通过get传参的方式传递一个id的参数,然后在后台处理

<a href='DeleteUser.ashx?id={0}

具体代码如下:

复制代码
using CZBK.ItcastProject.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;

namespace CZBK.ItcastProject.WebApp
{
    /// <summary>
    /// UserInfoList 的摘要说明
    /// </summary>
    public class UserInfoList : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            BLL.UserInfoService UserInfoService = new BLL.UserInfoService();
           List<UserInfo>list= UserInfoService.GetList();
           StringBuilder sb = new StringBuilder();
           foreach (UserInfo userInfo in list)
           {                                                                                 //点击删除跳转的地址                                                
               sb.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td><a href='DeleteUser.ashx?id={0}' class='deletes'>删除</a></td><td><a href='ShowDetail.ashx?uid={0}'>详细</a></td><td><a href='ShowEdit.ashx?id={0}'>编辑</a></td></tr>",userInfo.Id,userInfo.UserName,userInfo.UserPass,userInfo.Email,userInfo.RegTime);
           }
            //读取模板文件
           string filePath = context.Request.MapPath("UserInfoList.html");
           string fileCotent = File.ReadAllText(filePath);
           fileCotent = fileCotent.Replace("@tbody",sb.ToString());
           context.Response.Write(fileCotent);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
UserInfoList.ashx
复制代码

 

DeleteUser.ashx 相关代码展示如下

复制代码
using System;
using
System.Collections.Generic; using System.Linq; using System.Web; namespace CZBK.ItcastProject.WebApp { /// <summary> /// DeleteUser 的摘要说明 /// </summary> public class DeleteUser : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int id; // out id 就是指将值赋值给id if (int.TryParse(context.Request.QueryString["id"], out id)) { BLL.UserInfoService UserInfoService = new BLL.UserInfoService(); //如果删除成功 if (UserInfoService.DeleteUserInfo(id)) { //页面重定向 context.Response.Redirect("UserInfoList.ashx"); } else { context.Response.Redirect("Error.html"); } } else { context.Response.Write("参数错误!!"); } } public bool IsReusable { get { return false; } } } }
复制代码

2. 通过Ajax删除网页数据

 

posted @   锦大大的博客呀!  阅读(403)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示