- Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathProgram.cs
44 lines (38 loc) · 1.23 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
usingHtmx;
varapp=WebApplication.Create();
app.MapGet("/",()=>
{
varhtml="""
<!DOCTYPE html>
<html>
<head>
<style>
li[hx-get]{
cursor:pointer;
}
</style>
</head>
<body>
<h1>Click once</h1>
<ul>
<li hx-get="/htmx/once" hx-trigger="click once">Click</li>
<li hx-get="/htmx/unlimited" hx-trigger="click">Click</li>
</ul>
<script src="https://unpkg.com/htmx.org@2.0.0" integrity="sha384-wS5l5IKJBvK6sPTKa2WZ1js3d947pvWXbPJ1OmWfEuxLgeHcEbjUUA5i9V5ZkpCw" crossorigin="anonymous"></script>
</body>
</html>
""";
returnResults.Content(html,"text/html");
});
app.MapGet("/htmx/{key}",(HttpRequestrequest,stringkey)=>
{
if(request.IsHtmx()isfalse)
returnResults.Content("");
returnkeyswitch
{
"once"=>Results.Content($"This is the only result you are going to get {DateTime.UtcNow}"),
"unlimited"=>Results.Content($"You can continue to click {DateTime.UtcNow}"),
_ =>Results.Content("")
};
});
app.Run();