I am new to Blazor and trying to run Javascript runtime in Blazor Webassembly (using ABP framework) to store in the local storage, but for some reason I am getting UnsupportedJavaScriptRuntime Error. I tried the same in Blazor server side and it worked.
private async Task < Order > GetOrder() {
Order order = null;
var strOrder = await _jSRuntime.InvokeAsync < string > ("localStorage.getItem",
cstrShoppingCart);
if (!string.IsNullOrWhiteSpace(strOrder) && strOrder.ToLower() != "null")
order = JsonConvert.DeserializeObject < Order > (strOrder);
else {
order = new Order();
await SetOrder(order);
}
foreach(var item in order.LineItems) {
item.Product = await _productRepository.GetAsync(item.ProductId);
}
Below is the error
Microsoft.AspNetCore.Mvc.ViewFeatures.UnsupportedJavaScriptRuntime
System.InvalidOperationException HResult=0x80131509 Message=JavaScript interop calls cannot be issued during server-side prerendering, because the page has not yet loaded in the browser. Prerendered components must wrap any JavaScript interop calls in conditional logic to ensure those interop calls are not attempted during prerendering. Source=Microsoft.AspNetCore.Mvc.ViewFeatures StackTrace: at Microsoft.AspNetCore.Mvc.ViewFeatures.UnsupportedJavaScriptRuntime.Microsoft.JSInterop.IJSRuntime.InvokeAsync[TValue](String identifier, Object[] args) at Microsoft.JSInterop.JSRuntimeExtensions.InvokeAsync[TValue](IJSRuntime jsRuntime, String identifier, Object[] args) at BookStore.ShoppingCart.LocalStorage.ShoppingCart.d__11.MoveNext() in
JavaScript interop calls cannot be issued during server-side prerendering, because the page has not yet loaded in the browser. Prerendered components must wrap any JavaScript interop calls in conditional logic to ensure those interop calls are not attempted during prerendering.
I think the error message is clear.
User contributions licensed under CC BY-SA 3.0