Blazor Hello world
My colleague shared an article about ASP.NET Blazor how to implement "Web Assembly".Today, I try a classic sample, Of course, For new guys to enter the door "Hello world" is the best choice.
Setup
Opening the extension tool to search the word "blazor" you will find the package "ASP.NET Core Blazor Language Service".As you can see the name it means you need to be used ".Net core".
Choose Project Template
After installed, When we created a new project which will show more three templates.
- Basic Client Side Project,: Basically, this can run well but normally we will split it to client and backend so we don't use it.
- ServerAPI+Shared+Client Side: We use this, it is the most standard layer architecture.Ps: Template 1 and 2 will load assembly to browser through blazor.webassembly.js to render HTML.
- ServerAPI+Shared+Server Side: This is similar No.2 the different is it will not load assembly to the browser.All of the HTML will render from backed through blazor.server.js.
Notice, if the backend is unavailable client cannot render HTML.
Hello World
This sample uses No.2, it will have three projects as below shows:
- Client : Frontend View
- Server : Backed Web API, This is a primary running project.
- Shared : Shared project. e.g:Model
Testing, Just run the server project that can show the result. Which will load the client project to display.
About backed Web API
The server project has a sample code that demonstrates the client how to retrieve data from the backed.
SampleDataController.cs
Client View calling API
All of the above are generated by default setting. I didn't write any of the code.
Refference