Search code examples
blazorblazorise

Display an image in Blazorise Datagrid


I am currently working on an app which is supposed to display names, phone numbers, e-mails... and pictures. I've looked around on the internet to find out how to do it, but no results. Does anyone knows how to display an image in a cell ?

Thanks,

Romain.


Solution

  • So I found the answer to my question. To display an image, you simply have to use the <DisplayTemplate> element. Inside the <DisplayTemplate> block, you have to create a variable that will be an instance of your model.

    Here is a quick exemple on how to do it:

    ...
    <DataGridColumn TItem="MyModel" Field="@nameof(MyModel.Picture)" caption="">
        <DisplayTemplate>
            @{
                var myModel = context as MyModel;
                <img src="@myModel.Picture"/>
            }
        </DisplayTemplate>
    </DataGridColumn>
    ...