-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API Controllers routes isn't working on Blazor Server Side #9437
Comments
I had a similar problem when I tried to call a Razor Page from a Blazor Component using Server side Blazor. What worked for me was to add/re-add 'app.UserMvcDefaultRoute();' in the Configure method, Like you, I couldn't get it working with 'routes.MapControllers();' which I have seen being used on other examples like below:
Once I added 'app.UseMvcWithDefaultRoute();', my Blazor component with a NavLink was able to call href="home" which in turn hit my HomeController's Index.cshtml view. |
Thanks for taking the time @iamgmd!! If I re-add
This exception can be easily fixed by changing from:
to:
But I'm still unable to POST/GET anything to my API Controller. It is also worth noting that I can't use
P.S #2: All the blazor pages are working fine. It is just the controller that isn't. I'm unable to make any calls to it. This is my current using statements on the
|
@baartho I have tested calling an API controller using Preview 3 and don't seem to be having any issues after making the change. I am using a standard BlazorComponents project. Your Startup class seems to be a lot more advanced. Startup.cs
|
@baartho I installed VS2019 16.1.0 Preview 1.0 along with the nightly build of the dotnet SDK 3.0.100-preview4-011223, Created a BlazorComponent solution and changed the Startup.cs to be as below and I was able to call a MVC controller without problems. I will assume that this will work for an API controller as well. Hope this helps. Startup.cs
|
You can download the nightly build of dotnet from:
https://github.com/dotnet/core-sdk
From: baartho
Sent: 17 April 2019 17:34
To: aspnet/AspNetCore
Cc: Geoff Davis
Subject: Re: [aspnet/AspNetCore] API Controllers routes isn't working on Blazor Server Side (#9437)
I'm sorry but where did you download the SDK preview 4? I even looked for other branches of .NET Core on github but couldn't find.
https://github.com/dotnet/core/tree/master/release-notes
|
@iamgmd thank you very much!! I was able to POST and GET from a API Controller just fine! |
For anyone else experiencing this issue, see: https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-2.2&tabs=visual-studio#migrate-mvc-controllers |
@iamgmd I managed to complete the first part of this tutorial (https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/adding-controller?view=aspnetcore-3.0&tabs=visual-studio) following your code example. This problem is still present with the latest out-of-the-box Visual Studio 2019 setup as of today. |
Describe the bug
Defining routes / endpoints for API Controllers on a Blazor Server-Side project isn`t working. I had it working on previous Blazor versions but can't it to work on 0.9.0-preview3-19154-02.
To Reproduce
startup.cs code:
API Controller:
Expected behavior
Posting to https://localhost:xxxxx/api/Data/UploadPhoto
Or getting from: https://localhost:xxxxx/api/Data/Test should work.
The text was updated successfully, but these errors were encountered: