在Razor页面上显示自适应卡的语法

时间:2020-03-19 17:11:20

标签: c# asp.net-mvc razor adaptive-cards

剃刀/自适应卡新手在这里。我可以使用Adaptive Cards sdk在C#中创建自适应卡。但是文档没有显示如何在剃须刀页面上显示卡。

我的代码: C#页面模型

Python==3.6.3
flask==1.0.4
flask_restful==0.3.6

剃刀页面

 public PageResult OnGet()
        {
            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);
            ViewData.Add("cardJson",renderedCard.Html);

            return Page();
        }

剃须刀页面仅以字符串形式显示格式为html的卡数据。我在文档中看不到有关如何在剃须刀页面上实际渲染卡片的任何内容。有人可以提供正确语法的帮助吗?

1 个答案:

答案 0 :(得分:0)

这有效:

    string cardJson = "{\r\n    \"type\": \"AdaptiveCard\",\r\n    \"body\": [\r\n        {\r\n            \"type\": \"Image\",\r\n            \"altText\": \"\",\r\n            \"url\": \"https://placekitten.com/408/287\",\r\n            \"id\": \"idKittenPicture\"\r\n        },\r\n        {\r\n            \"type\": \"TextBlock\",\r\n            \"text\": \"Nice kitty\",\r\n            \"id\": \"idKittyText\"\r\n        },\r\n        {\r\n            \"type\": \"Input.Text\",\r\n            \"placeholder\": \"type something here\",\r\n            \"id\": \"idInput\",\r\n            \"isMultiline\": true\r\n        },\r\n        {\r\n            \"type\": \"ActionSet\",\r\n            \"actions\": [\r\n                {\r\n                    \"type\": \"Action.OpenUrl\",\r\n                    \"title\": \"Rosie\'s Page Button\",\r\n                    \"id\": \"idRosiePage\",\r\n                    \"url\": \"https://jwt.io/\"\r\n                }\r\n            ]\r\n        }\r\n    ],\r\n    \"$schema\": \"http://adaptivecards.io/schemas/adaptive-card.json\",\r\n    \"version\": \"1.0\"\r\n}";
    AdaptiveCardRenderer renderer = new AdaptiveCardRenderer();

    AdaptiveCard card = AdaptiveCard.FromJson(cardJson).Card;

    var adaptiveSubmitAction = new AdaptiveSubmitAction();
    adaptiveSubmitAction.Title = "Data";
    adaptiveSubmitAction.Data = "{\"id\":123456789,\"name\":\"Abner Wallace\"}";
    card.Actions.Add(adaptiveSubmitAction);
    RenderedAdaptiveCard renderedCard = renderer.RenderCard(card);

    HtmlString htmlString = new HtmlString(renderedCard.Html.ToString());
}
@htmlString