Skip to content

docs(Upload): Improve Upload controller documentation #2782

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

Merged
merged 4 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions components/upload/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,8 @@ var builder = WebApplication.CreateBuilder(args);

// ...

builder.Services.AddControllers();

var app = builder.Build();

// ...
Expand Down
9 changes: 6 additions & 3 deletions components/upload/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is unclear here. "depends on the application and it outside the..." Please, revise.


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

<div class="skip-repl"></div>
Expand Down
12 changes: 11 additions & 1 deletion components/upload/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -41,6 +41,16 @@ The Remove action may return `HTTP 415 Unsupported Media Type`.
This means that the Remove action method expects `IEnumerable<string>` 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:
Expand Down
Loading