-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathModelBindingUsageHandler.cs
More file actions
35 lines (32 loc) · 1.03 KB
/
ModelBindingUsageHandler.cs
File metadata and controls
35 lines (32 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ServiceComposer.AspNetCore;
namespace Snippets.ModelBinding
{
class ModelBindingUsageHandler : ICompositionRequestsHandler
{
// begin-snippet: model-binding-bind-body-and-route-data
[HttpPost("/sample/{id}")]
public async Task Handle(HttpRequest request)
{
var requestModel = await request.Bind<RequestModel>();
var body = requestModel.Body;
var aString = body.AString;
var id = requestModel.Id;
//use values as needed
}
// end-snippet
}
class ModelBindingTryBindUsageHandler : ICompositionRequestsHandler
{
// begin-snippet: model-binding-try-bind
[HttpPost("/sample/{id}")]
public async Task Handle(HttpRequest request)
{
var (model, isModelSet, modelState) = await request.TryBind<RequestModel>();
//use values as needed
}
// end-snippet
}
}