SaaS CMS has officially launched! Learn more now.

Taghelpers epi-property vs ProperyFor with parameters



Is there a way to send viewdata parameters with use of taghelper epi-property?

<div epi-property="@Model.CurrentPage.ImageAsContentReference" />

The equivalence with HtmlHelpers:

@Html.PropertyFor(m => Model.CurrentPage.ImageAsContentReference, new { width = 300, height = 300, format = "webp"});

then i can further down in the stack get the data with "ViewData" in my displaytemplate

Apr 13, 2023 10:22

Im looking for something like this:

but when testing <div epi-property="@Model.CurrentPage.ImageAsContentReference" view-data='@(new ViewDataDictionary(ViewData) { {  "width", 300 },{ "height", 300},{ "format", "webp" } })' />

it is rendering

<div view-data="Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary">      ... content comes here ... </div>

Apr 13, 2023 13:21
Eric - Dec 05, 2023 11:17
Did you solve this or get any help fixing this problem?
Luc Gosso (MVP) - Dec 05, 2023 13:06
Seems not to be possible yet...

We wanted the block to know their context, so we ended up using TempData in the MVC Views...

TempData["whereAmI"] = "left";
Html.PropertyFor(m => m.CurrentContent.LeftContentArea)

and then in the block view:

string whereAmI = TempData["whereAmI"] != null ? TempData["whereAmI"].ToString() : string.Empty;

Dec 05, 2023 13:05
Ted - Dec 12, 2023 15:10
I know an easier way to render images... :D

With tag helpers you dont necessarily need to even use additional properties like this. For instance, in your example:

@Html.PropertyFor(m => Model.CurrentPage.ImageAsContentReference, new { width = 300, height = 300, format = "webp"});

At least for the width and height, you can just add them to the tag:

<div epi-property="@Model.CurrentPage.ImageAsContentReference" width="300" height="300" />

Im a little less clear on the format property, so in that case, that might not work. What does that tag do? You could conceivably make a custom taghelper just to handle the 'format' piece. So, your taghelper would target a div and render certain attributes depending on the value. So, two tag helpers on the same tag. Im fairly certain that would work.

Edited, Dec 29, 2023 13:42
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.