本文整理汇总了C#中System.Web.Mvc.JsonResult类的典型用法代码示例。如果您正苦于以下问题:C# JsonResult类的具体用法?C# JsonResult怎么用?C# JsonResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonResult类属于System.Web.Mvc命名空间,在下文中一共展示了JsonResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GatherNumbers
public JsonResult GatherNumbers(string runname)
{
var theColleciton = GetCollection();
var query = theColleciton.AsQueryable<ServerStat>()
.Where(s => s.runName.ToLower() == runname.ToLower())
.ToList();
var someStats = query
.GroupBy(stat =>
new
{
NodeName = stat.osHostName
})
.Select(stat => new
{
NumberOfTransactions = stat.Count(),
Node = stat.Key.NodeName
})
.ToList();
var jsonObject = new JsonResult();
jsonObject.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
jsonObject.MaxJsonLength = int.MaxValue;
jsonObject.Data = someStats;
return jsonObject;
}
示例2: Get
public JsonResult Get()
{
JsonResult result = new JsonResult();
//var t = bll.GetCompanyEventList(1, 500);
// return Json(t, JsonRequestBehavior.AllowGet);
return result;
}
示例3: CategoryList
public JsonResult CategoryList(string e)
{
JsonResult rez = new JsonResult();
List<Category> cats = con.Categorys.OrderBy(c => c.Por).ToList();
rez.Data = RenderPartialViewToString("CategoryList", cats);
return rez;
}
示例4: DeleteRedirect
public JsonResult DeleteRedirect(string id)
{
var result = new JsonResult();
try
{
if (String.IsNullOrEmpty(id))
{
return result;
}
var redirectId = Int32.Parse(id);
var redirect = Context.Redirects.FirstOrDefault(x => x.RedirectId == redirectId);
Context.Redirects.Remove(redirect);
Context.SaveChanges();
// recycle cache after save
CachedObjects.GetRedirectsList(true);
result.Data = new {success = true};
return result;
}
catch
{
result.Data = new { success = false };
return result;
}
}
示例5: AddToCompDivision
//由未匹配科室表插入匹配科室
public JsonResult AddToCompDivision(string HospitalCode, string HZType, string HZCode, string Type, string Code)
{
var user = Session["CurrentUser"] as UserAndRole;
var res = new JsonResult();
int TypeInt = Convert.ToInt32(Type);
bool flag = _ServicesSoapClient.SetMpDivisionCmp(HospitalCode, TypeInt, Code, HZCode, "手动匹配", user.UserId, user.TerminalName, user.TerminalIP, user.DeviceType);
if (flag)
{
flag = _ServicesSoapClient.ChangeStatusForTmpDivision(HospitalCode, HZType, HZCode, 2);
if (flag)
{
res.Data = true;
}
else
{
res.Data = false;
}
}
else
{
res.Data = false;
}
res.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
return res;
}
示例6: JsonpResult
/// <param name="jsonResult">The <see cref="JsonResult" /> to convert to a <see cref="JsonpResult" />.</param>
public JsonpResult(JsonResult jsonResult)
{
ContentEncoding = jsonResult.ContentEncoding;
ContentType = jsonResult.ContentType;
Data = jsonResult.Data;
JsonRequestBehavior = jsonResult.JsonRequestBehavior;
}
示例7: OAuthInit
public JsonResult OAuthInit()
{
JsonResult jr = new JsonResult();
jr.ContentType = "text/json";
jr.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
try
{
Client Sina = null;
OAuth oauth = new OAuth(CnfgConst.Sina_AppKey, CnfgConst.Sina_AppSecret, CnfgConst.Sina_CallbackUrl);
Sina = new Client(oauth); //用cookie里的accesstoken来实例化OAuth,这样OAuth就有操作权限了
//if (!string.IsNullOrEmpty(code))//暂时无法获取到传回的URL
//{
// var token = oauth.GetAccessTokenByAuthorizationCode(code);
// string accessToken = token.Token;
// Response.Cookies["AccessToken"].Value = accessToken;
// jr.Data = new { isSuccess = true };
// //Response.Redirect("Default.aspx");
//}
//else
{
string url = oauth.GetAuthorizeURL();
jr.Data = new { isSuccess = false, url = url };
}
return jr;
}
catch (Exception)
{
throw;
}
}
示例8: Login
public ActionResult Login()
{
//Response.ContentType = "application/json";
//// Post方式下,取得client端传过来的数据
//if ("post".Equals(Request.HttpMethod.ToLower()))
//{
// StreamReader reader = new StreamReader(Request.InputStream);
// string json = HttpUtility.UrlDecode(reader.ReadToEnd());
// Response.Write(json);
//}
//// Get方式下,取得client端传过来的数据
//else
//{
// Response.Write("[{\"title\":\"Java高级编程\"},{\"title\":\"C#高级编程\"},{\"title\":\"JavaScript高级编程\"}]");
//}
//var d = Request.Params.GetValues("username");
string username = "姓名:"+Request.Params["username"];
string age ="年龄:"+ Request.Params["age"];
var result = new JsonResult { Data = new { username, age }};
result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
return result;
}
示例9: Application_Error
protected void Application_Error()
{
var httpContext = HttpContext.Current;
if (httpContext == null) return;
var context = new HttpContextWrapper(System.Web.HttpContext.Current);
var routeData = RouteTable.Routes.GetRouteData(context);
var requestContext = new RequestContext(context, routeData);
/* when the request is ajax the system can automatically handle a mistake with a JSON response. then overwrites the default response */
if (requestContext.HttpContext.Request.IsAjaxRequest())
{
httpContext.Response.Clear();
var controllerName = requestContext.RouteData.GetRequiredString("controller");
var factory = ControllerBuilder.Current.GetControllerFactory();
var controller = factory.CreateController(requestContext, controllerName);
var controllerContext = new ControllerContext(requestContext, (ControllerBase)controller);
var jsonResult = new JsonResult
{
Data = new {success = false, serverError = "500"},
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
jsonResult.ExecuteResult(controllerContext);
httpContext.Response.End();
}
else
{
httpContext.Response.Redirect("~/Error");
}
}
示例10: SearchKullaniciYetki
public ActionResult SearchKullaniciYetki(string searchAdi, string searchSoyadi, int? page)
{
var Jr = new JsonResult
{
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
var KullaniciList = baglanti().Select<Kullanici>();
if (!string.IsNullOrEmpty(searchAdi))
{
KullaniciList = KullaniciList.Where(p => p.adi.ToLower().Contains(searchAdi)).ToList();
}
if (!string.IsNullOrEmpty(searchSoyadi))
{
KullaniciList = KullaniciList.Where(p => p.soyadi.ToLower().Contains(searchSoyadi)).ToList();
}
var Match = new YetkilendirmeViewModel()
{
};
Match.Kullanicilar = KullaniciList;
if (KullaniciList != null)
{
var Result = RenderPartialViewToString("YetkilendirmeList", Match);
Jr.Data = new[] { new { Status = "ok", results = Result, searchAdi = searchAdi } };
}
return Jr;
}
示例11: DeleteSchema
public JsonResult DeleteSchema(string id)
{
var result = new JsonResult()
{
Data = new { success = false, message = "There was an error processing your request." }
};
if (String.IsNullOrEmpty(id))
{
return result;
}
int moduleId = Int32.Parse(id);
var module = Context.Schemas.FirstOrDefault(x => x.SchemaId == moduleId);
Context.Schemas.Remove(module);
var success = Context.SaveChanges();
if (success > 0)
{
BookmarkUtil.DeleteBookmarkForUrl("/admin/schemas/editschema/" + id + "/");
result.Data = new { success = true, message = "The schema has been successfully deleted." };
}
return result;
}
示例12: OnException
protected override void OnException(ExceptionContext filterContext)
{
if (filterContext.HttpContext.IsCustomErrorEnabled || true) //IsCustomErrorEnabled always false if client is localhost or client and server IPs identical. True set to override.
{
filterContext.ExceptionHandled = true;
// If this is an ajax request, return the exception in the response
if (filterContext.HttpContext.Request.IsAjaxRequest())
{
//if (HttpContext.Response.ContentType == "text/html")
//{
// filterContext.HttpContext.Response.StatusCode = 500;
// var json = new JsonResult();
// json.JsonRequestBehavior = JsonRequestBehavior.AllowGet; //SICHERHEITSPROBLEM: s. http://haacked.com/archive/2009/06/25/json-hijacking.aspx
// json.Data = HttpUtility.UrlEncode(filterContext.Exception.Message); // +filterContext.Exception.StackTrace;
// json.ExecuteResult(this.ControllerContext);
//}
//else
//{
filterContext.HttpContext.Response.StatusCode = 500;
var json = new JsonResult();
json.JsonRequestBehavior = JsonRequestBehavior.AllowGet; //SICHERHEITSPROBLEM: s. http://haacked.com/archive/2009/06/25/json-hijacking.aspx
json.Data = HttpUtility.UrlEncode(filterContext.Exception.Message); // +filterContext.Exception.StackTrace;
json.ExecuteResult(this.ControllerContext);
//}
}
else
{
ViewData.Model = new System.Web.Mvc.HandleErrorInfo(filterContext.Exception, "ControllerName", "ActionName");
// Pass a flag to the view to tell it whether or not to show a the stack trace
ViewBag.IsCustomErrorEnabled = true; //filterContext.HttpContext.IsCustomErrorEnabled;
this.View("Error").ExecuteResult(this.ControllerContext);
}
}
}
示例13: Delete
public ActionResult Delete(Guid id)
{
JsonResult jsresult = new JsonResult();
jsresult.ContentType = Consts.CONTENT_TYPE;
jsresult.Data = new { result = bizSysMenu.DeleteSysMenuByID(id) };
return jsresult;
}
示例14: StartGame
public JsonResult StartGame(PraetorianGameState playerSideChoosen)
{
var jResult = new JsonResult();
if(playerSideChoosen == PraetorianGameState.ASSASSINTURN)
{
//Human needs to make the first move, so set the game state and return out
_Board.IsAssassinComputer = false;
_Board.IsLegalMove = true;
_Board.GameState = PraetorianGameState.ASSASSINTURN;
PraetorianBoard.ComputerState = PraetorianGameState.PRAETORIANTURN;
}
else
{
_Board.IsAssassinComputer = true;
PraetorianBoard.ComputerState = PraetorianGameState.ASSASSINTURN;
PraetorianGameSetup pGame = new PraetorianGameSetup(_Board.Pieces.ToList(), new KeyValuePair<int, PraetorianPieceViewModel>(0, new PraetorianPieceViewModel() { }));
var newBoard = pGame.ComputerMakeMove(GAMEDEPTH, true);
_LastMove = new KeyValuePair<int, PraetorianPieceViewModel>(_iMoveNumber++, GetLastMovedPieceFromComputer(newBoard.BoardPieces, _Board.Pieces.ToList()));
_MasterMoveList.Add(_LastMove);
_Board.Pieces = newBoard.BoardPieces;
_Board.GameState = PraetorianGameState.PRAETORIANTURN;
_Board.IsLegalMove = true;
}
jResult = Json(_Board);
return jResult;
}
示例15: OnActionExecuted
/// <summary>
/// Called by the ASP.NET MVC framework after the action method executes.
/// </summary>
/// <param name="filterContext">The filter context.</param>
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
if (filterContext == null || !filterContext.HttpContext.Request.IsAjaxRequest())
{
return;
}
// Preparing Json object for AJAX.success processing in forms.js javascript
string destinationUrl = string.Empty;
if (filterContext.Result is RedirectResult)
{
var result = filterContext.Result as RedirectResult;
destinationUrl = UrlHelper.GenerateContentUrl(result.Url, filterContext.HttpContext);
}
if (filterContext.Result is RedirectToRouteResult)
{
var result = filterContext.Result as RedirectToRouteResult;
var helper = new UrlHelper(filterContext.RequestContext);
destinationUrl = helper.RouteUrl(result.RouteValues);
}
// Rendered context is getting reloaded by AJAX.success in forms.js javascript
if (filterContext.Result is ViewResult)
{
return;
}
var jsonResult = new JsonResult { Data = new { resultType = "Redirect", redirectUrl = destinationUrl } };
filterContext.Result = jsonResult;
}