diff --git a/components/upload/events.md b/components/upload/events.md index adc7bc597..55e106b07 100644 --- a/components/upload/events.md +++ b/components/upload/events.md @@ -783,6 +783,8 @@ var builder = WebApplication.CreateBuilder(args); // ... +builder.Services.AddControllers(); + var app = builder.Build(); // ... diff --git a/components/upload/overview.md b/components/upload/overview.md index 6f3ef8959..ad23ef40d 100644 --- a/components/upload/overview.md +++ b/components/upload/overview.md @@ -69,14 +69,17 @@ Steps 4 and 5 are optional, but strongly recommended. * The correct binding source attribute for the file name argument is `[FromForm]`. Set it explicitly if you are using an [`[ApiController]` attribute](https://learn.microsoft.com/en-gb/aspnet/core/web-api/). * Use the Upload [`OnRemove` event](slug:upload-events#onremove) to [send additional custom data with the file](slug:upload-events#send-custom-data-with-the-file) as an argument to the `Remove` controller method. -Both action methods must accept `POST` requests. Correct request routing depends on the application. +Both action methods must accept `POST` requests. -The `UploadController` class below assumes that the project name and namespace is `TelerikBlazorUpload`. +Request routing depends on the application and it outside the Upload component's scope. Normally, the following two statements in the server project's `Program.cs` are enough: -Make sure to enable controller routing in the app startup file (`Program.cs`). In this case, `app.MapDefaultControllerRoute();` is all that's needed. +* `builder.Services.AddControllers();` +* `app.MapDefaultControllerRoute();`. Also check the [Upload Troubleshooting](slug:upload-troubleshooting) page. +The `UploadController` class below assumes that the project name and namespace is `TelerikBlazorUpload`. + >caption Sample Upload Controller
diff --git a/components/upload/troubleshooting.md b/components/upload/troubleshooting.md index 0805727f7..2421f2873 100644 --- a/components/upload/troubleshooting.md +++ b/components/upload/troubleshooting.md @@ -26,7 +26,7 @@ The action method is hit, but the method argument is `null` ## HTTP 400 Bad request -The action method is not hit and the server returns HTTP 400 Bad request. +The action method is not hit and the server returns `HTTP 400 Bad request`. * Make sure that [controller routing is enabled and configured correctly](https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/routing). For example, the controller samples in this documentation use `[Route("api/[controller]/[action]")]`. It is enough to add `app.MapDefaultControllerRoute();` to `Program.cs` in the default Blazor project template. [Web API controllers require explicit `[Route]` configuration](https://learn.microsoft.com/en-gb/aspnet/core/web-api/?view=aspnetcore-8.0#attribute-routing-requirement). * Make sure that the `[Route]` attribute in the upload controller (if set) is compatible with `SaveUrl` and `RemoveUrl`. @@ -41,6 +41,16 @@ The Remove action may return `HTTP 415 Unsupported Media Type`. This means that the Remove action method expects `IEnumerable` and .NET does not infer the correct binding source. Set a `[FromForm]` [binding source attribute](https://learn.microsoft.com/en-gb/aspnet/core/web-api/?view=aspnetcore-8.0#binding-source-parameter-inference) to the file name argument. +## HTTP 405 Method Not Allowed + +The action method is not hit and the server returns `HTTP 405 Method not allowed`. + +Make sure that [controller routing is enabled](https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api) in the server-side project's startup file (`Program.cs`). Normally, the following two statements are required: + +* `builder.Services.AddControllers();` +* `app.MapDefaultControllerRoute();`. + + ## Connection Error and No Response The server does not return any response. The browser console shows connection errors like: