- Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathProgram.cs
45 lines (37 loc) · 1.47 KB
/
Program.cs
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
36
37
38
39
40
41
42
43
44
45
usingMicrosoft.AspNetCore.Mvc;
varbuilder=WebApplication.CreateBuilder();
builder.Services.AddControllersWithViews();
varapp=builder.Build();
app.MapDefaultControllerRoute();
app.Run();
publicclassGreetingParams
{
publicintUserId{get;set;}
publicstringName{get;set;}
publicboolIsAmazing{get;set;}
publicshort?Age{get;set;}
publicoverridestringToString()=>$"User Id: {UserId}, Name: {Name}, Is Amazing: {IsAmazing}, Age: {Age}";
}
publicclassHomeController:Controller
{
publicActionResultIndex([FromQuery]GreetingParamsgreet)
{
returnnewContentResult
{
Content=$@"<html><body>
<h1>Class binding with [FromQuery]</h1>
<p>You can see the difference in behavior between the nullable type and non nullable types here. Age is short? and User Id is int.<p>
{greet}
<ul>
<li><a href=""/"">/</a></li>
<li><a href=""/?name=annie"">/?name=annie</a></li>
<li><a href=""/?isamazing=true"">/?isamazing=true</a></li>
<li><a href=""/?userid=1"">/?userid=1</a></li>
<li><a href=""/?age=33"">/?age=33</a></li>
<li><a href=""/?userid=1&name=annie&isamazing=true"">/?userid=1&name=annie&isamazing=true&age=33</a></li>
</ul>
</body></html>",
ContentType="text/html"
};
}
}