31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
using Htmx.ApiDemo.Templates.Components;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Htmx.ApiDemo.Templates;
|
|
|
|
public sealed class Greeting : GreetingBase
|
|
{
|
|
public required int Count { get; init; }
|
|
public required string Username { get; init; }
|
|
public required Guid GreetingId { get; init; }
|
|
|
|
protected override void RenderCountButton(HtmxRenderContext context)
|
|
{
|
|
var button = new Button(
|
|
$"Click to increase count {Count}",
|
|
"outline",
|
|
hxAttrs: $"hx-get=\"/greet/{Username}/{Count}/{GreetingId}\"" +
|
|
$" hx-target=\"#Greeting-{GreetingId}\" hx-swap=\"outerHTML\""
|
|
);
|
|
button.Render(context);
|
|
}
|
|
|
|
protected override void RenderUser(HtmxRenderContext context)
|
|
=> context.Writer.WriteUtf8(Username.ToUtf8Bytes());
|
|
protected override void RenderGreetingId(HtmxRenderContext context)
|
|
=> context.Writer.WriteUtf8(GreetingId.ToString().ToUtf8Bytes());
|
|
protected override void RenderSeparator(HtmxRenderContext context)
|
|
=> new Separator().Render(context);
|
|
}
|