本文整理汇总了C#中System.Web.Mvc.JsonResult类的典型用法代码示例。如果您正苦于以下问题:C# JsonResult类的具体用法?C# JsonResult怎么用?C# JsonResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonResult类属于System.Web.Mvc命名空间,在下文中一共展示了JsonResult类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:ExtraordinaryJerks,项目名称:HackNashvilleStats,代码行数:26,代码来源:StatsController.cs
示例2: Get
public JsonResult Get()
{
JsonResult result = new JsonResult();
//var t = bll.GetCompanyEventList(1, 500);
// return Json(t, JsonRequestBehavior.AllowGet);
return result;
}
开发者ID:tomfang678,项目名称:SmartWeb,代码行数:7,代码来源:CompanyEventController.cs
示例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;
}
开发者ID:MichalLasak,项目名称:megazlonet,代码行数:7,代码来源:AdminController.cs
示例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;
}
}
开发者ID:codevlabs,项目名称:DirigoEdge,代码行数:29,代码来源:RedirectController.cs
示例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;
}
开发者ID:wangykelsi,项目名称:CDMIS,代码行数:27,代码来源:DictController.cs
示例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;
}
开发者ID:KatoTek,项目名称:Encompass,代码行数:8,代码来源:JsonpResult.cs
示例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;
}
}
开发者ID:dannywj,项目名称:MyHeart,代码行数:34,代码来源:UserController.cs
示例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;
}
开发者ID:rockhe168,项目名称:android,代码行数:26,代码来源:UserController.cs
示例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");
}
}
开发者ID:itverket,项目名称:geek-retreat,代码行数:31,代码来源:Global.asax.cs
示例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;
}
开发者ID:elektroengin,项目名称:MvcServiceStackOrm,代码行数:34,代码来源:TanimController.cs
示例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;
}
开发者ID:hyrmedia,项目名称:DirigoEdge,代码行数:26,代码来源:SchemasController.cs
示例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);
}
}
}
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:34,代码来源:BaseController.cs
示例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;
}
开发者ID:dalinhuang,项目名称:sz-oasys,代码行数:7,代码来源:SysMenuManageController.cs
示例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;
}
开发者ID:dalorna,项目名称:WebProjects,代码行数:27,代码来源:PraetorianController.cs
示例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;
}
开发者ID:targitaj,项目名称:m3utonetpaleyerxml,代码行数:35,代码来源:FormValidatorAttribute.cs
示例16: JsonResult
/// <summary>
/// 发送返回统一格式的JsonResult
/// </summary>
/// <param name="controller">控制器方法</param>
/// <param name="message">消息</param>
/// <param name="result">结果 ok error noLogin</param>
/// <param name="data">数据</param>
/// <param name="redirectURL">跳转URL</param>
/// <returns></returns>
public static JsonResult JsonResult(this Controller controller, E_JsonResult result, string message, object data, string redirectURL)
{
ResponseMsgInfo rpInfo;
if (redirectURL != null && redirectURL != "")
{
rpInfo = new ResponseMsgInfo();
rpInfo.Result = result.ToString();
rpInfo.Message = message;
rpInfo.Data = data;
rpInfo.RedirectURL = controller.Url.Content(redirectURL); //注意转换成绝对路径
}
else
{
rpInfo = new ResponseMsgInfo()
{
Result = result.ToString(),
Message = message,
Data = data
};
}
JsonResult jsr = new JsonResult();
jsr.Data = rpInfo;
jsr.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
return jsr;
}
开发者ID:uuhoo,项目名称:Reports,代码行数:35,代码来源:ControllerExtension.cs
示例17: GetBillData
// GET api/Bill
public object GetBillData(string url)
{
JsonResult jsonResult = new JsonResult();
try
{
using (var client = new WebClient())
{
var jsonData = client.DownloadString(url);
var jsonSerializerSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() };
object model;
using (GlimpseTimeline.Capture("====> Get bills from Json URL AngularJS"))
{
model = CacheHandler.Get(homeAngularJSCacheKey, () =>
{
return JsonConvert.DeserializeObject<BillModel>(jsonData, jsonSerializerSettings);
});
}
jsonResult = new JsonResult
{
Data = model,
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
}
}
catch (Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(ex.Message));
}
return jsonResult.Data;
}
开发者ID:rg911,项目名称:SkyBillViewDemo,代码行数:34,代码来源:BillAPIController.cs
示例18: getLanguages
public JsonResult getLanguages(int page, int records, string orderBy, string orderDirection)
{
JsonResult result = null;
var query = (from l in db.Language
select new DTOLanguage
{
Id = l.Id,
Name = l.Name,
IsActive = l.IsActive,
LngCdId = l.LanguageCode.Code
}).OrderBy(string.Format("{0} {1}", orderBy, orderDirection)).Skip((records * page) - records).Take(records);
result = new JsonResult()
{
Data = new
{
Languages = query.ToList(),
Count = (from l in db.Language
select l).Count()
}
};
return result;
}
开发者ID:emacho,项目名称:HorizonCMS,代码行数:27,代码来源:LanguagesController.cs
示例19: AddCategory
public JsonResult AddCategory(string name)
{
var result = new JsonResult();
if (!String.IsNullOrEmpty(name))
{
using (var context = new DataContext())
{
var newCategory = new BlogCategory
{
CategoryName = name,
CreateDate = DateTime.Now,
IsActive = true
};
context.BlogCategories.Add(newCategory);
context.SaveChanges();
result.Data = new {id = newCategory.CategoryId};
return result;
}
}
return result;
}
开发者ID:marciocamello,项目名称:dirigo-edge,代码行数:26,代码来源:CategoryController.cs
示例20: AddRedirect
public JsonResult AddRedirect(String source, String destination, Boolean isPermanent, Boolean rootMatching)
{
var result = new JsonResult();
try
{
var redirect = new Redirect
{
Source = source,
Destination = destination,
IsPermanent = isPermanent,
RootMatching = rootMatching,
DateModified = DateTime.UtcNow,
IsActive = true
};
Context.Redirects.Add(redirect);
Context.SaveChanges();
result.Data = new
{
id = redirect.RedirectId,
success = true
};
CachedObjects.GetRedirectsList(true);
return result;
}
catch
{
result.Data = new { success = false };
return result;
}
}
开发者ID:codevlabs,项目名称:DirigoEdge,代码行数:31,代码来源:RedirectController.cs
注:本文中的System.Web.Mvc.JsonResult类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论