Skip to content

Commit 4e3e68e

Browse files
Merge dimodi-patch-2-2782 into production (#2783)
* docs(Upload): Improve Upload controller documentation * Update Upload overview.md * Update components/upload/overview.md * Update troubleshooting.md --------- Co-authored-by: Dimo Dimov <961014+dimodi@users.noreply.github.com>
1 parent f757b29 commit 4e3e68e

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

components/upload/events.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,8 @@ var builder = WebApplication.CreateBuilder(args);
783783

784784
// ...
785785
786+
builder.Services.AddControllers();
787+
786788
var app = builder.Build();
787789

788790
// ...

components/upload/overview.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,17 @@ Steps 4 and 5 are optional, but strongly recommended.
6969
* 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/).
7070
* 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.
7171

72-
Both action methods must accept `POST` requests. Correct request routing depends on the application.
72+
Both action methods must accept `POST` requests.
7373

74-
The `UploadController` class below assumes that the project name and namespace is `TelerikBlazorUpload`.
74+
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:
7575

76-
Make sure to enable controller routing in the app startup file (`Program.cs`). In this case, `app.MapDefaultControllerRoute();` is all that's needed.
76+
* `builder.Services.AddControllers();`
77+
* `app.MapDefaultControllerRoute();`.
7778

7879
Also check the [Upload Troubleshooting](slug:upload-troubleshooting) page.
7980

81+
The `UploadController` class below assumes that the project name and namespace is `TelerikBlazorUpload`.
82+
8083
>caption Sample Upload Controller
8184

8285
<div class="skip-repl"></div>

components/upload/troubleshooting.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The action method is hit, but the method argument is `null`
2626

2727
## HTTP 400 Bad request
2828

29-
The action method is not hit and the server returns HTTP 400 Bad request.
29+
The action method is not hit and the server returns `HTTP 400 Bad request`.
3030

3131
* 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).
3232
* 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`.
4141
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.
4242

4343

44+
## HTTP 405 Method Not Allowed
45+
46+
The action method is not hit and the server returns `HTTP 405 Method not allowed`.
47+
48+
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:
49+
50+
* `builder.Services.AddControllers();`
51+
* `app.MapDefaultControllerRoute();`.
52+
53+
4454
## Connection Error and No Response
4555

4656
The server does not return any response. The browser console shows connection errors like:

0 commit comments

Comments
 (0)