Class JsonResult
Defines a model for a result of a request that is serialized as JSON.
public class JsonResult : ActionResult, IStatusCodeActionResult, IActionResult
- Inheritance
-
JsonResult
- Implements
- Inherited Members
- Extension Methods
Constructors
JsonResult(object, HttpStatusCode, JsonSerializerOptions?)
Initializes a new instance of the JsonResult class with the object to serialize.
public JsonResult(object value, HttpStatusCode statusCode = HttpStatusCode.OK, JsonSerializerOptions? serializerOptions = null)
Parameters
valueobjectThe value object to serialize.
statusCodeHttpStatusCodeThe expected result HTTP status code.
serializerOptionsJsonSerializerOptionsThe JSON serializer options for serializing the result.
Properties
SerializerOptions
Gets the JSON serializer options for serializing the result.
public JsonSerializerOptions? SerializerOptions { get; }
Property Value
StatusCode
Gets the expected result HTTP status code.
public int? StatusCode { get; }
Property Value
- int?
Value
Gets the value object to serialize.
public object Value { get; }
Property Value
Methods
ExecuteResultAsync(ActionContext)
Executes the result operation of the action method asynchronously writing the Value to the response.
public override Task ExecuteResultAsync(ActionContext context)
Parameters
contextActionContextThe context in which the result is executed.
Returns
- Task
An asynchronous operation.
Exceptions
- ArgumentNullException
Thrown if
contextis null.