home / software / tips and tricks / What is the ObjectResult Class in Microsoft.AspNetCore.Mvc?

What is the ObjectResult Class in Microsoft.AspNetCore.Mvc?

Updated:  10/15/2017 14:10 PM
Author:  Shiju Mathews

Status:    Resolved.


An ObjectResult is special in the MVC framework because when we return an ObjectResult, the MVC framework looks at this object. This object needs to be represented in the HTTP response.
This object should be serialized into XML or JSON or some other format and ultimately, the decision will be made based on the configuration information that you give to the MVC at startup. If you don't configure anything, you just get some defaults, and the default is a JSON response.

Consider a class Employee


On the Home controller, Index method add the following.
Save all your files and refresh the browser. You will see the following output.
{"id":1,"name":"Shiju Mathews"}
Tags: What is the ObjectResult Class in Microsoft.AspNetCore.Mvc?
Updated on: November 2024