Tom Sawyer
Tom Sawyer

Reputation: 857

Values are blanks when returned from the API

The json values are blank when calling this code from the API:

    [Route("api/[controller]")]
    public class ReportDesignerSetupController : ControllerBase
    {
        [HttpPost("[action]")]
        public object GetReportDesignerModel([FromForm] string reportUrl)
        {
             return Ok(new JavaScriptSerializer().Deserialize<object>("{name: \"Seb\", age: 42, gender: \"M\"}"));
        }
    }

{
  "name": [],
  "age": [],
  "gender": []
}

Does anybody has any reason the value are blanks?

Thank you very much!

Reference:

I am debugging a project related to DevEXpress.

https://community.devexpress.com/blogs/aspnet/archive/2019/12/03/reporting-for-blazor-how-to-use-document-viewer-and-report-designer-in-server-side-blazor-apps.aspx

Upvotes: 0

Views: 73

Answers (2)

cycaHuH
cycaHuH

Reputation: 3460

Try to use Newtonsoft.Json if you can. Just tried this code locally and it works just fine

    [HttpGet("test")]
    public IActionResult GetReportDesignerModel([FromForm] string reportUrl)
    {
        return Ok(JsonConvert.DeserializeObject("{name: \"Seb\", age: 42, gender: \"M\"}"));
    }

From Postman

from Postman

Upvotes: 1

chety
chety

Reputation: 156

How do you call your web api(url) from postman/insomnia .. etc ? It seems you are returning a data(GET) but your method is marked as [HttpPost("[action]")]. Could you edit the method as HttpGet and try?

Upvotes: 0

Related Questions