ASP. net mvc custom processing JSON ActionResult class, jsonactionresult
1. Unify the JSON format and specify the ContentType to solve the problem of downloading when the ContentType is set to application/json when the browser of a lower version obtains the json format.
public abstract class CustomResult<TData> : ActionResult { public abstract TData GetObject(); protected JsonSerializerSettings SerializerSettings; protected void InitSerialization(ControllerContext context) { HttpResponseBase response = context.HttpContext.Response; response.ContentType = "text/html"; TData data = GetObject(); if (SerializerSettings == null) { SetSerializerSettings(); } response.Write(JsonConvert.SerializeObject(data, Formatting.None, SerializerSettings)); } protected virtual void SetSerializerSettings() { SerializerSettings = new JsonSerializerSettings { Converters = new List<JsonConverter> { new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd hh:mm" } } }; } public override void ExecuteResult(ControllerContext context) { InitSerialization(context); } }
In aspnet MVC, no actionResult is written in the controller. What is the difference between writing an application? What can be done?
By default, the controller in mvc returns an actionresult (action, result). You can also return htmlresult, jsonresult, view, And, which are subclasses of actionresult. First, it is a return type. The difference between the global application object written to the application can be distinguished from the next layer. Or I didn't understand what it meant to you, and asked if you had any questions.
In the Controller of Aspnet MVC, what should I do when the JsonResult method of the returned type needs to jump to other actions?
Change public JsonResult Exchange to public ActionResult Exchange.