开发者

how do I create a custom WebGrid Column

开发者 https://www.devze.com 2023-03-25 02:55 出处:网络
i need to add an additional column to my WebGrid, the new colume s开发者_运维问答hould contain an HTML5 audio based on one of the record\'s fields. something like that:

i need to add an additional column to my WebGrid, the new colume s开发者_运维问答hould contain an HTML5 audio based on one of the record's fields. something like that:

    <audio controls="controls">
        <source src="@string.Format("{0}{1}", @item.SongID.ToString(), ".mp3")" type="audio/mp3"/>
        Your browser does not support the audio element.
    </audio>

does webgrid supports such a scenario?

Thank! ofer


Here's one way of doing it. Inside your view create a helper and use it for column format:

@helper AudioTag(dynamic item)
{
    <audio controls="controls">
        <source src="@string.Format("{0}.mp3", item.SongID)" type="audio/mp3"/>
        Your browser does not support the audio element.
    </audio>
}

<div>
    @grid.GetHtml(columns: grid.Columns(
                                grid.Column("Audio", format: a => AudioTag(a))));
</div>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号