1

In index.cshtml @functions I am able to retrieve data from DB, while sending the argument chosenDate as shown under:

trackList = await Http.GetJsonAsync>("/api/Lopstat/Tracks/" + chosenDate.ToString("yyyy-MM-dd"));

What if I want to send two arguments with my request? Is this possible?

1 Answer 1

2

If you want to send two arguments, you can define a class with two fields for these arguments. This class will automatically be JSON-encoded and sent as a string

You can use the SendJsonAsync method whose signature is displayed below:

  public static async Task<T> SendJsonAsync<T>(this HttpClient httpClient, HttpMethod method, string requestUri, object content)

// And this is how you can use it in your code...
trackList = await Http.SendJsonAsync<Change this to the return type>( HttpMethod.Get, "/api/Lopstat/Tracks", MyObject);   
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for answering my first question on Stackoverflow! I will try out this solution.
I found that this works, but I had to change HttpMethod.Get to HttpMethod.Post

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.