2

Good Day Guys,

How to pass multiple parameter in blazor GetFromJsonAsync, I get error when using this code.

blazor webassembly

data= await http.GetFromJsonAsync<dataobject[]>($"api/Sample/Get/{id}/{date}");

.net core api

    [HttpGet("Get/{id}/{date}")]
    public ActionResult<List<dataobject>> Get(string id, string date)
    {
        
        
    }
user8551826
  • 21
  • 1
  • 4
  • 1
    As far as I can see, that seems correct, whats the error you are getting? Share your error or issue in more details – Umair Sep 19 '20 at 23:58
  • This is the error I get. Unhandled exception rendering component: The provided ContentType is not supported; the supported types are 'application/json' and the structured syntax suffix 'application/+json'. – user8551826 Sep 20 '20 at 00:10
  • The api works when using POSTMAN, but i can't make it run in blazor webassembly – user8551826 Sep 20 '20 at 00:18
  • 1
    I get it now, I'm passing date with format yyyy/MM/dd, just change it to yyyy-MM-dd. – user8551826 Sep 20 '20 at 00:26
  • For an explanation about the error, see https://stackoverflow.com/a/63863447/60761 – H H Sep 20 '20 at 04:56
  • @user8551826 - the way to round this up is to post a self-answer or maybe to just delete the question. – H H Sep 20 '20 at 04:57

1 Answers1

1

As you mentioned in the comment of your question you are using date as this format yyyy/MM/dd which means the / is considered as URL path. So you will need to URL encode your date which will become like this yyyy%2FMM%2Fdd which is now safe to send as URL path.

You can use HttpUtility.UrlEncode for URL encoding. Details here

Umair
  • 4,864
  • 3
  • 28
  • 47