SummaryContent & DetailContent not working in NotificationMessage

I copied this from your demo but I'm getting errors.

    void ShowNotificationWithCustomContent()
    {
        NotificationService.Notify(new NotificationMessage
        {
            Severity = NotificationSeverity.Warning,
            Duration = 40000,
            SummaryContent = ns =>@<RadzenText TextStyle = "TextStyle.H6" > Custom summary: < br /> @DateTime.Now </RadzenText >,
            DetailContent = ns => @<RadzenButton Text = "Clear" Click = "@(args => ns.Messages.Clear())" />
        });
    }

If I use Summary & Detail, it's fine. I tried html inside Detail but that doesn't work.

Not sure what I'm doing wrong.

Such code can be used in razor file only - you cannot use it in plain code cs file.

Thank you for your reply.

What's the equivalent of this in code behind ie. how do I specify DetailContent in codebehind for NotificationMessage?

Does Detail in NotificationMessage not support any html?

Injecting HTML in Blazor can be vulnerable and that’s why RenderFragment should be used. Check official Microsoft documentation on this topic:

Keep in mind that there is no problem to have code in both razor @code blocks and the cs file since they are partial classes.

Thank you.

I understand why Detail doesn't allow html. All I want to achieve is a multiline notification message. What's the easiest way to achieve this without writing the same @code wherever it's used

NotificationService.Notify(new NotificationMessage() { Severity = NotificationSeverity.Error, Summary = $"Error", Detail = $"Paragraph 1. Paragraph 2" });

You can check my reply here: Multi Line in DialogService.Confirm() - #14 by korchev

Here is something that will work in a regular C# file:

NotificationService.Notify(new NotificationMessage
{
  Severity = NotificationSeverity.Warning,
  Duration = 40000,
  SummaryContent = ns => builder => builder.AddMarkupContent(0, "<strong>Summary</strong>"),
  DetailContent = ns => builder => builder.AddMarkupContent(0, "Paragraph 1 <br />Paragraph 2")
});

Thank you @korchev. I'll give that a try

That works fine.

Thank you.