Passing additional ViewData
Asp.NET MVC
Now as the name suggests, ViewData might get you thinking about just that. Whereas there's a quite simple way to get your extra data across to a Display or Editor Template.
This time the simplest answer is the one, though not the obvious one.
Pass across your additionalViewData like you normally would
@Html.DisplayFor( modelItem => item.ImageId, new { Class = "thumb-sm" } )
Then access if from your template using a simple ViewBag dynamic object.
File Path /Views/Shared/DisplayTemplates/TemplateName.cshtml
In this case we're passing along an additional class intended to allow us to control the size of the image rendered on the page. Haven't tried this in older versions of MVC, this will work in 4 & 5
Hope this helps someone, thought I'd put it up here as I forgot and spent a few minutes searching my code for the answer.
Thanks for reading.
Comments
Post a Comment