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)
    {
        
        
    }
6
  • 1
    As far as I can see, that seems correct, whats the error you are getting? Share your error or issue in more details Commented Sep 19, 2020 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'. Commented Sep 20, 2020 at 0:10
  • The api works when using POSTMAN, but i can't make it run in blazor webassembly Commented Sep 20, 2020 at 0:18
  • 1
    I get it now, I'm passing date with format yyyy/MM/dd, just change it to yyyy-MM-dd. Commented Sep 20, 2020 at 0:26
  • For an explanation about the error, see stackoverflow.com/a/63863447/60761 Commented Sep 20, 2020 at 4:56

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.