博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MVC Ajax.BeginForm 实例
阅读量:4567 次
发布时间:2019-06-08

本文共 2511 字,大约阅读时间需要 8 分钟。

 在<head>引用

 

在<body>编辑HTML

//指定提交到Home控制器下的Login方法 //HttpMethod  指定提交方式为Post //OnSuccess 返回方法为AfterAdd //id id名称为frmSet //type="submit" 按钮类型为 submit @using (Ajax.BeginForm("Login","Home", new { }, new AjaxOptions() { HttpMethod = "Post", OnSuccess = "AfterAdd" }, new { id = "frmSet" }))        {        
  • See? Another one
}

 Home 控制器 Login方法

[HttpPost]        public ActionResult Login(FormCollection form)        {            string msg = "";            string usernmae = Common.Tool.GetSafeSqlandHtml(Request ["username"]);            string pwd = Common.Tool.GetSafeSqlandHtml(Request["pwd"]);            string checkCode = Common.Tool.GetSafeSqlandHtml(Request["CheckCode"]);            if (Session["ValidataCode"] == null || checkCode != Session["ValidataCode"].ToString())            {                return Json(new { isok = "erro", msg = "验证码错误" });            }            if (string.IsNullOrEmpty(usernmae) || string.IsNullOrEmpty(pwd))            {                return Json(new { isok = "erro", msg = "用户名或密码不能为空" });            }            pwd = Common.Tool.Md5(pwd).ToUpper();            MODEL.User us = BLL.User.SelectModel("userName='" + usernmae + "' and PassWord='" + pwd + "' ");            if (us == null)            {                msg = "用户名或密码错误";            }            else            {                if (us.Status == 1)                {                    return Json(new { isok = "erro", msg = "该管理员已被禁用" });                }                else                {                     MODEL.LoginLog ulogin = new MODEL.LoginLog();                    ulogin.Uid = us.Id;                    ulogin.UserID = us.UserName;                    ulogin.UserName = us.Name ;                    ulogin .IP  = Common .Tool .GetClientIp ();                    System.Web.HttpContext Current = System.Web.HttpContext.Current;                    ulogin.LoginWeb = Current.Request.ServerVariables["HTTP_USER_AGENT"];                    ulogin.AddTime = DateTime.Now;                    BLL.LoginLog.Add(ulogin);                    Current.Session["User"] = us;                    string goUrl = "/Cms/Default/Index";                    return Json(new { isok = "ok", gourl = goUrl });                }            }            return Json(new { isok = "erro", msg = msg });        }

 编辑返回方法AfterAdd

 

最后,完成!

转载于:https://www.cnblogs.com/mobobo/p/5543970.html

你可能感兴趣的文章
服务器上centos 7 配置静态IP
查看>>
C# unsafe模式内存操作深入探索
查看>>
Redis拾遗(一)
查看>>
js字符串转换为Json对象的三种写法
查看>>
Is it possible to display icons in a PopupMenu?
查看>>
制作导航条
查看>>
iOS中的内存管理1
查看>>
23种设计模式全解析
查看>>
Learning Python 008 正则表达式-003 sub()方法
查看>>
要检测两个C文件的代码的抄袭情况
查看>>
iOS开发之应用内支付IAP全部流程
查看>>
【web技术】html特效代码(一)
查看>>
SWFObject: 基于Javascript的Flash媒体版本检测与嵌入模块
查看>>
高可用集群搭建
查看>>
Lua学习笔记
查看>>
Redis监控工具,命令和调优
查看>>
zabbix-mysql迁移分离
查看>>
jQuery调用WCF 说明
查看>>
算法第5章作业
查看>>
7.9 练习
查看>>