Reputation: 4066
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
Upvotes: 6
Views: 9140
Reputation: 6528
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)
Upvotes: 9
Reputation: 4470
Try it like this:
@RenderImage(image, x => x.Image, new ImageParameters { Width = 100}, isEditable: true)
As of recent version of Glass - the only possible solution is
@RenderImage(image, x => x.Image, new { Width = 100}, isEditable: true)
Also you can take a look at - TUTORIAL 16 - RENDERING IMAGES
Upvotes: 6