Blazor WebAssembly API Controller
Hi all, I am pretty new in C#. Now, I'm working on a Blazor web project. My project structure is like that:
|
MealOrdering
(Blazor WebAssembly) ( MealOrdering.Server.Data and MealOrdering.Shared added as dependent projects)
| MealOrdering.Server.Data
(Class Library)
| MealOrdering.Shared
(Class Library)
I created models in MealOrdering.Server.Data
, DTOs in MealOrdering.Shared
, services in MealOrdering
. Also added AutoMapper package to MealOrdering
and created Services/Extensions/ConfigureMappingExtension.cs
.
Finally, in MealOrdering
, I created a folder which is named Controllers
and a API Controller which is named UserController.cs
. I added a method for handling GET request.
However, when I go to https://localhost:44325/api/User/Users
, it returns Not Found... What should I do to get users?
Project structure has been attached.
I tried my best so hope it's clear to get help.
5 Replies
You can't put controllers in WASM. WASM is client side, you would need to make a separate project for the API and call that api from WASM for serverr side stuff
wow, got it. thank you
also
.Server.Data
is a redundant project. Just put them in your Api projectthanks, actually I can’t determine what is necessary now. just trying to learn something. I was watching a blazor series which uses .net 5.
I think i need to find a newer one.
Yes the latest version is .Net 9 now