How do you add an ASP.NET web API to the default SERVER ASP.NET Blazor Default Generated Solution

362 views Asked by At

What is the best approach to add a web api as a project to the default ASP.NET Blazor solution? When using visual studio 2019 you no longer get the server and web projects when you select Blazor server on create new solution/project.

I found a way be browsing serveral blogs but it was mentioned that microsoft might dis-continue this.

Looking for the best way.
The reason I need to add an API to an ASP.NET Blazor Side project is to so the SyncFusion DataGrid can bind to it. See: https://blazor.syncfusion.com/documentation/datagrid/data-binding/#entity-framework

Here is what I am thinking of trying:

Use "options.EnableEndpointRouting" approach.

  • Step 1: Create an API folder
  • Step 2: Right Click/Add New/ Controller/Web API Step
  • Modify Startup.cs with:

using Microsoft.AspNetCore.Mvc;

services.AddMvc(options => options.EnableEndpointRouting = false).SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

app.UseMvcWithDefaultRoute();

Is this considered a future safe or supported way to do it?

Server Side Blazor Created By VS 2019 Wizard:

enter image description here

Solution generated looks like: enter image description here

1

There are 1 answers

0
OpTech Marketing On BEST ANSWER

I got in touch with Syncfusion Support and they provided a sample of using their data grid to skip the API.

The example at the link below actually has Entity Framework calls right in the Blazor page code. I implemented with a service wrapping the Entity Framework.

Works great. Also used this same approach with Dapper.

https://www.syncfusion.com/forums/165744/how-to-add-a-supporting-web-api-and-routing-to-support-databinding-in-sf-grid-on-blazor

enter image description here