question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor - How to read .json file in client side synchronous way or have any callback function for Http.GetJsonAsync method

See original GitHub issue

In blazor client side application, can read and data from json file async way.

protected override async Task OnInitAsync()
{
        DBModel data = await Http.GetJsonAsync<DBModel>("sample-data/data.json");
}

But i want to do it in synchronous approach, because i need to do route the page after data fetch completed. I have tried like this below code

protected override void OnInit()
{
        DBModel data = Http.GetJsonAsync<DBModel>("sample-data/data.json");
        UriHelper.NavigateTo('Dashboard');
}

Getting below error message

Error CS0029 - Cannot implicitly convert type System.Threading.Tasks.Task<Application1.Models.DBModel>’ to ‘Application1.Models.DBModel’

Or advice how to route a page after data fetch got success. Is any callback handler available for achieve my case?

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
enetstudiocommented, Jun 2, 2019

@pandiyaraj678, this is not my solution. This is your code, a copy of your code, which is why it is “(“Dashboard”)” instead of “(”/Dashboard")". Do you get it ? I just copy paste your code, and said that there is nothing wrong with it. This is how it should be, though I would design my code much differently.

Anyhow, your new code snippet, which you say is working, is actually the first code snippet implemented in two methods, and thus, if it works as two methods, it should work as a single combined method.

And that is what I’ve said that there in nothing wrong with your code…

As suggested above, you’d better post such questions in StackOverflow

Good day…

1reaction
mkArtakMSFTcommented, May 31, 2019

Hi. It looks like this is a question about how to use ASP.NET Core. While we do our best to look through all the issues filed here, to get a faster response we suggest posting your questions to StackOverflow using the asp.net-core-mvc tag.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I read a JSON file in Blazor WebAssembly?
Use the HttpClient class with the GetFromJsonAsync() method to read a JSON file in Blazor WebAssembly. Follow these steps to read the JSON...
Read more >
how to make Blazor HTTP Get JSON ASYNC request?
I'm using blazor in an application, but found some problem with server call. I created a simple API controller with the name of...
Read more >
How to do synchronous calling of HttpClient in Blazor-blazor
Basically you shouldn´t do a synchronous Http call. Preferable option: var result = await HttpClient.GetJsonAsync<T>(myUrl);. This is the solution if you ...
Read more >
Alternative to httpClient.GetFromJsonAsync() that provides ...
I am learning Blazor Wasm. I make a api call to an api that doesn't exist, something like var resultObj = await httpClient....
Read more >
How to download an in-memory object as a JSON file ...
I have a class containing some info a user might want to download after visiting a page. MyClass.cs public class MyClass { public...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found