display grid value using webforms in umbraco

2019-09-11 01:39发布

问题:

I am trying to display a document property in my webform template in umbraco, like this:

<%@ Master Language="C#" MasterPageFile="~/umbraco/Masterpages/Default.master" AutoEventWireup="true" %>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <umbraco:item field="content" runat="server" />

</asp:Content>

But on the content i am getting a json description of the field, not the value, here is the output:

{ "name": "1 column layout", "sections": [ { "grid": 12, "rows": [ { "name": "Headline", "areas": [ { "grid": 12, "hasConfig": false, "controls": [ { "value": "
This is the content i am adding

", "editor": { "alias": "rte" }, "active": true } ] } ], "hasConfig": false, "id": "31604cf5-c263-0d98-8978-67e07390adff" } ] } ] }

Image attached

How can i just display the value property?

Thanks

回答1:

Oh, you're using a Grid datatype. Then I don't think you can use the umbraco:item thingy anyways, sorry :-s

Here's a list of ways to render grid HTML, but the examples are using Razor / MVC: https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/grid-layout/render-grid-in-template

You could try something like this:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <%= CurrentPage.GetGridHtml("content") %>
</asp:Content>

If none of the examples in the list works, grids might not be supported in Web Forms. Consider using the (more modern) MVC and Razor approach instead - you could install the Fanoe starter kit on a fresh installation and see how it's done?