How to add a class attribute to sitecore MVC image

2019-09-05 18:34发布

问题:

Using Sitecore mvc field render

@Html.Sitecore().Field("FieldName", ContentItem)

I would like to add class to image tag like below,

<img src="/images/Sample.jpg" class="hidden-xs">

So, How can I add the css class in Site core MVC image field.

Thanks in advance.

回答1:

You can simply use this one.

@Html.Sitecore().Field("FieldName", Model.PageItem, new { @class="large-image", @mw="250" })