DotNet.invokeMethodAsync() Does Not Invoke C# Method In Blazor Component Using Microsoft Edge Browser
Hello,
Cheers!
Here's an odd error of DotNet.invokeMethodAsync() that I encountered. This method works for both Google Chrome and Mozilla Firefox but not on Microsoft Edge. The code below will just call a weather API and deliver a response payload to the C# caller function. I
window.checkWeather = (cityName) => { const API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" return new Promise((resolve, reject) => { fetch(`https://api.openweathermap.org/data/2.5/weather?q=${cityName}&appid=${API_KEY}&units=metric`) .then(res => { if (!res.ok) { console.error(`HTTP error: ${res.status}`); } DotNet.invokeMethodAsync('WeatherApplication', 'ShowWeatherContainer'); return res.json(); }) .then(data => { resolve(data); }) .catch(error => reject(error)) }) }
After doing some research both on Blazor github issues, Microsoft Edge forums and modifying the browser settings, the solution that made this work is to delete all browsing data of the MS Edge browser. After doing that, DotNet.invokeMethodAsync() works as expected.
Cheers!
Comments
Post a Comment