Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code sample on .NET HTML Client on rendering adaptive card #88

Closed
SigmaSolutions opened this issue Aug 14, 2018 — with docs.microsoft.com · 3 comments
Closed

Comments

Copy link

Would .NET HTML rendering also apply to Razor page of MVC?

Would it be possible to provide a code sample on .NET HTML client to demonstrate how the adaptive card be rendered? Thanks.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@matthidinger
Copy link
Collaborator

You could call the renderer API from a Razor View if you want to inject the HTML in it. I don't have a code sample but it should be relatively straight forward using Razor's docs to call APIs

Please see here for a C# sample: https://docs.microsoft.com/en-us/adaptive-cards/sdk/rendering-cards/net-html/render-a-card

Please let us know if that doesn't answer your question

@PeggyWiltz
Copy link

PeggyWiltz commented Mar 19, 2020

This documentation shows how to create the html in the c# class but not how to display it on the page. The Razor documentation is not helpful either. Just adding the razor page to this example in the documentation would be extremely helpful.

Edit: Update on previous comment - code example
I have tried this code both in the razor page as shown here, and with the code in a C# class, adding the rendered html to a ViewData object and displaying that on the razor page. Both give the same result. I only see the adaptive card as a string with the html tags.

What is missing between creating the renderer.RenderCard(card) and using it on the page?

@page
@using AdaptiveCards
@using AdaptiveCards.Rendering.Html
@model ScoutAdaptiveCardRenderer.Pages.Card.CardRenderModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
    ViewData["Title"] = "CardRender";
}
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    @{
        AdaptiveCardRenderer renderer = new AdaptiveCardRenderer();

        AdaptiveCard card = new AdaptiveCard(renderer.SupportedSchemaVersion);
        card.Body.Add(new AdaptiveTextBlock { Text = "Hello World" });
        AdaptiveTextInput adaptiveTextInput = new AdaptiveTextInput { IsMultiline = true };
        card.Body.Add(adaptiveTextInput);
        AdaptiveActionSet adaptiveActionSet = new AdaptiveActionSet();
        adaptiveActionSet.Actions.Add(new AdaptiveOpenUrlAction()
        {
            Id = "buttonId",
            Title = "Button"
        });
        card.Body.Add(adaptiveActionSet);
        RenderedAdaptiveCard renderedCard = renderer.RenderCard(card);
    }
    @renderedCard.Html
</body>
</html>

Copy link

@PeggyWiltz I believe you need to wrap this line:

@renderedCard.Html

In the raw HTML helper that Razor provides as follows:

@Html.Raw(renderedCard.Html)

You can review the docs for this method here: https://docs.microsoft.com/en-us/dotnet/api/system.web.mvc.htmlhelper.raw?view=aspnet-mvc-5.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants