Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor Server Side Console.WriteLine not working

Tags:

blazor

I am wondering if i am missing something but just started a basic template for server side Blazor and find that Console.WriteLine does not work. By that I mean I can't see the text in Chrome Console.

@code{

    protected override async Task OnInitializedAsync() 
    {
        System.Console.WriteLine("oninit");
    }
}
like image 561
AliK Avatar asked Sep 02 '19 02:09

AliK


People also ask

Is Blazor server side rendered?

Blazor Server Hosting Model ASP.NET Core apps can be configured to use Blazor Server as the hosting model, which means that the app is executed on the server side instead of in a browser.

How do I get console WriteLine Output in Visual Studio?

In Visual Studio uppermost menu choose Debug > Windows > Output. It shows all Console. WriteLine("Debug MyVariable: " + MyVariable) when you get to them.

How does Blazor server side work?

Server-side Blazor is executed on the server within an ASP.NET Core application. All UI updates, event handling, and JavaScript calls are handled from server by using a SignalR connection, even a button click will go to server.

Is Blazor client side or server side?

Blazor is a web framework for building web UI components (Razor components) that can be hosted in different ways. Razor components can run server-side in ASP.NET Core (Blazor Server) versus client-side in the browser on a WebAssembly-based . NET runtime (Blazor WebAssembly, Blazor WASM).


1 Answers

I had to do something like this to make text show in the browser console:

@inject IJSRuntime jsRuntime

@code {

    protected override async Task OnInitializedAsync()
    {
        await jsRuntime.InvokeAsync<string>("console.log", "hello world");
    }
}
like image 180
Nick Kuznia Avatar answered Sep 17 '22 16:09

Nick Kuznia