Nandy
Nandy

Reputation: 25

.NET 5 WEB API not returning response in postman and browser

.NET 5 WEB API not returning response in postman and browser. Please help me to resolve this issue. Here is the code:

using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Mime;
using System.Text;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using RestSharp;

namespace WebAPIApplication.Controllers
{
    [Route("api")]
    [ApiController]
    [Produces(MediaTypeNames.Application.Json)]
    [Consumes(MediaTypeNames.Application.Json)]
    public class ApiController : ControllerBase
    {


        [HttpGet("public")]
        public IActionResult myPublic()
        {
            MyStatus _status = new MyStatus();
            return Ok(_status);
        }
    }
}

Here is the response: {}

Upvotes: 1

Views: 413

Answers (1)

Fei Han
Fei Han

Reputation: 27793

return Ok(_status);

Here is the response: {}

Please check and make sure you defined properties well in your class MyStatus, perhaps you defined them as fields not properties, which cause this issue.

public class MyStatus
{
    public int StatusCode;
    //...

To fix the issue, can modify it as below

public class MyStatus
{
    public int StatusCode { get; set; }
    //...

Upvotes: 1

Related Questions