Jefferson S. Motta

Jefferson S. Motta

  • 611
  • 2.7k
  • 89.9k

Blazor, call Server Side Controller from .razor page

Feb 7 2020 3:44 PM
I'm using Blazor, the last preview:
 
On razor page, I'm trying using:
 
await Http.PostJsonAsync("api/ValuesController", addItem);
 
This is my Controller:
 
[Route("api/Controller")]
public class ValuesController : Controller
// POST api/<controller>
[HttpPost]
public void Post([FromBody]WeatherForecast value)
{
value.MyMethod();
I'm registering on server:
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
endpoints.MapFallbackToClientSideBlazor<Client.Program>("index.html");
endpoints.MapControllerRoute(name: "DefaultApi", pattern: "api/{controller}");
});
}
 
But here is occurring error 404: await Http.PostJsonAsync("api/ValuesController", addItem);
 
What Am I missing?