Glass mapper Render Image data attributes

Gabbar picture Gabbar · Oct 20, 2014 · Viewed 7.7k times · Source

I'm trying to render a image field with RenderImage. I need some data- attributes in the image but I can't seem to figure out how to go about implementing that. I've tried this but doesn't work

@RenderImage(image, x => x.Image, new RenderingParameters("data-protect=true"), isEditable: true)   

Thanks

Answer

Michael Edwards picture Michael Edwards · Oct 21, 2014

Although the answer above will work I am going to be removing ImageParameters support in the future and moving to just anonymous type support:

@RenderImage(image, x => x.Image, new { Width = 100}, isEditable: true)

The reason for this change is because having a strongly type class like ImageParameters is very limiting. Anonymous types are also a common way of doing this with other frameworks so it would fit with what everyone else is doing.

Updated to include rendering of data attributes:

@RenderImage(image, x => x.Image, new { data_protect = "true"}, isEditable: true)