Blazor - How to read .json file in client side synchronous way or have any callback function for Http.GetJsonAsync method
See original GitHub issueIn 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:
- Created 4 years ago
- Comments:10 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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…
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.