0

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

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

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.