Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

JS.InvokeAsync do not return anything

$
0
0

I want to read window.devicePixelRatio in javascript from C# in ASP Core Blazor.

This is my javascript in wwwroot/index.html:

<body><script>        function PixelRatio()        {            return window.devicePixelRatio;        }</script>    ...

And in Index.razor, I trying to call it like this:

    @inject IJSRuntime JS    protected override void OnAfterRender(bool firstRender)    {        base.OnAfterRender(firstRender);        if (firstRender)        {            GetDevicePixelRatio();        }    }    private async Task GetDevicePixelRatio()    {        Console.WriteLine("GetDevicePixelRatio Calling"); // This shows in Output-log        m_dpiScale = await JS.InvokeAsync<double>("PixelRatio");        Console.WriteLine("GetDevicePixelRatio Called with value " + m_dpiScale); // This is not called.    }

I expected the returnvalue be 2.5, but the second Console.WriteLine is not called, I dont know if the InvokeAsync is hanning, or if it throws an silence exception, but nothing i can see.

I can debug in javascript in function PixelRatio() but nothing happens when it returns.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>