.NET MVC 登录提交返回json实体
来源:互联网 发布:java获取最近三个月 编辑:程序博客网 时间:2024/05/16 05:54
控制器中通过调用<pre class="csharp" name="code">OperateContext.CurrentContext.PackagingAjaxMsg("ok", "登录成功", null, "/Home/Index");返回json实体
using System.Web;using System.Web.Mvc;using Model;using IBLL;using Web.Helper;using Common;namespace Web.Logic{ public class HomeController:Controller { #region 处理登录的信息 /// <summary> /// 处理登录的信息 /// </summary> /// <returns></returns> [HttpPost] public ActionResult LoginIn() { OperateContext oc =OperateContext.CurrentContext; string strLoginName = Request.Form["name"]; string strLoginPwd = Request.Form["pwd"]; Ou_UserInfo usr=oc._IBLLSession.IOu_UserInfoBLL.Login(strLoginName, strLoginPwd); if (usr != null) { //把登录信息保存到Session中 Session["loginUser"] = usr; //返回json信息 JsonResult ss = OperateContext.CurrentContext.PackagingAjaxMsg("ok", "登录成功", null, "/Home/Index"); //msg = new message(true, "Success"); //AjaxMsgModel ann = new AjaxMsgModel //{ // Msg = "登录成功", // Statu = "ok", // Data = null, // BackUrl = "/Home/Index" //}; //return Json(ann); return ss; } else { //返回json信息 return OperateContext.CurrentContext.PackagingAjaxMsg("err", "登录失败", null); } } #endregion }}
</pre><pre class="csharp" name="code">
将要返回的json实体
<pre class="csharp" name="code">using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Model{ public class AjaxMsgModel { public string Msg { get; set; } public string Statu { get; set; } public string BackUrl { get; set; } public object Data { get; set ; } }}
封装方法将把ajax返回值封装成json格式的返回值
<pre class="csharp" name="code">封装方法将把ajax返回值封装成json格式的返回值 #region 把ajax返回值封装成json格式的返回值 /// <summary> /// 把ajax返回值封装成json格式的返回值 /// </summary> /// <param name="statu">ajax状态</param> /// <param name="msg">ajax信息</param> /// <param name="data">ajax数据</param> /// <param name="backurl">调用后的链接</param> /// <returns></returns> public JsonResult PackagingAjaxMsg(string statu, string msg, object data = null, string backurl = "") { AjaxMsgModel ann = new AjaxMsgModel { Msg = msg, Statu = statu, Data = data, BackUrl = backurl }; JsonResult ajaxRes = new JsonResult(); ajaxRes.Data = ann; ajaxRes.JsonRequestBehavior = JsonRequestBehavior.AllowGet; return ajaxRes; } #endregion
</pre><pre class="csharp" name="code"><pre class="javascript" name="code"><script type="text/javascript"> $('#LoginDialog').dialog({ title: '登录', width: 400, height: 200, closed: false, cache: false, modal: true, buttons: [{ iconCls:'icon-edit', text:'登录', handler: function () { $.ajax({ type: "POST", url: "/Home/LoginIn", data:{ name: $("#tableForm input[name=UName]").val(), pwd: $("#tableForm input[name=UPwd]").val(), }, cache: false, dataType: "json", success: function (data) { if (data.Statu == "ok") { window.location = data.BackUrl; } else { alert(data.Msg); } } }); } }, { iconCls:'icon-ok', text:'注册', handler: function () { } }] }); function ok(jsonData) { $.procAjaxMsg(jsonData, function () { window.location = jsonData.BackUrl; }, function () { alert("登录失败"); }) }; </script>
0 0
- .NET MVC 登录提交返回json实体
- MVC AJAX提交JSON 数据转换实体类型
- asp.net mvc jquery 提交json数据
- ASP.NET MVC Jquery提交Json数据
- JQuery调用.NET MVC 返回 Json
- MVC使用Newtonsoft无需实体类,实现JSON数据返回给前端页面使用
- asp.net mvc ajax上传文件 然后返回json
- ASP.NET MVC 3 JSON 返回时间格式处理
- asp.net mvc实现rest风格返回json
- AngularJS处理ASP.Net MVC Json返回日期
- asp.net MVC控制器返回json问题总结
- asp.net mvc c# 读取json文件返回字符串
- Spring MVC返回JSON
- MVC Json 的返回
- spring MVC返回JSON
- spring MVC 返回json
- spring MVC 返回json
- spring mvc 返回 json
- java线程池
- 单片机
- MySQL锁的用法之表级锁
- 289. Game of Life
- [Webservice] Eclipse根据wsdl文件自动生成webservice的调用客户端
- .NET MVC 登录提交返回json实体
- 常见算法
- Android开发安装sutdio以及环境配置
- android 和iOS的区别和联系《个人记录》
- 使用TransitionDrawable实现多张图片淡入淡出的效果
- centos使用rpm安装mysql
- 子类继承父类,new 一个子类对象的过程(待完善)
- qt控件
- Maven简介(一)——Maven的安装和settings.xml的配置