Giter Site home page Giter Site logo

Comments (3)

matthidinger avatar matthidinger commented on August 17, 2024

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

from adaptivecards.

PeggyWiltz avatar PeggyWiltz commented on August 17, 2024

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>

from adaptivecards.

uncheckederror avatar uncheckederror commented on August 17, 2024

@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

from adaptivecards.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.