Best approach to strip HTML tags from a string in Blazor Datagrid

1 Answer 1280 Views
Grid
Tom
Top achievements
Rank 1
Tom asked on 27 Sep 2021, 11:43 PM

Hi,

I was wondering what is the best approach to strip out the HTML of a text field that is displayed in a Blazor Datagrid.

I tried using the Template feature along with MarkupString as shown below but it just returns the name of the field rather than the contents of it.

<TelerikGrid Data="Model.CurrentPageData" TotalCount="Model.TotalItemCount" OnRead="ReadItems" Pageable="true" PageSize="10" Groupable="true" Sortable="false">
    <GridColumns>
        <GridColumn Field="@(nameof(Escalation.EscalationId))" Title="Escalation ID" Width="120px" />
        <GridColumn Field="@(nameof(Escalation.CaseType))" Title="Type" Width="120px" />
        <GridColumn Field="@(nameof(Escalation.SummaryOfRequest))" Title="Request Summary" Width="120px" />
            <Template>
                    @((MarkupString)(nameof(Escalation.SummaryOfRequest)))               
            </Template>
        </GridColumn>
        <GridColumn Field="@(nameof(Escalation.PrimaryBu))" Title="Primary BU" Width="120px" />
        <GridColumn Field="@(nameof(Escalation.CreatedDate))" Title="Created" DisplayFormat="{0:dddd, dd MMM yyyy}" Width="120px" />
    </GridColumns>
</TelerikGrid>


1 Answer, 1 is accepted

Sort by
0
Matthias
Top achievements
Rank 5
Bronze
Bronze
Iron
answered on 28 Sep 2021, 06:46 AM

Hi Tom,
nameof(Escalation.SummaryOfRequest) will always return the name of the field as a string. 

 

Here is a code snippet on how to display the content:

...

 <Template>

var myHtml = (MarkupString) "<b>hello</b> <i>world</i>"; @myHtml;

</Template>

 


Best regards
Matthias

Tags
Grid
Asked by
Tom
Top achievements
Rank 1
Answers by
Matthias
Top achievements
Rank 5
Bronze
Bronze
Iron
Share this question
or