Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
I'm using uComponents Multi-Node Tree Picker for the first time. I have a custom datatype 'Promotors' that stores promotors:
My Razor-script to render the promotors looks like this:
@if (Model.HasValue("Promotors")){ <p>Promotors: @foreach (var promotor in @Model.Promotors) { @promotor.InnerText } </p>}
However, this only renders the id of the stored promotor
How can I render the value of the stored promotor?
Thanks for your help,Anthony
Hi Anthony.
you have to get the node Object by the id and then you can acsses any property of this node...
@foreach (var promotor in @Model.Promotors) {dynamic node = new DynamicNode(promotor.InnerText);<span>@node.Name</span> /// or - @node.properyAlias }
Hope that help. cheers.
Hi gilad,
Yes that helps :)
Tweaked my code a little:
@using umbraco.MacroEngines@inherits umbraco.MacroEngines.DynamicNodeContext<h1>@Model.Name</h1>@if (Model.HasValue("Promotors")){ <p>Promotors: @foreach (var id in @Model.Promotors) { dynamic promotor = new DynamicNode(id.InnerText); @promotor.Name } </p>}
This works.
Thanks a lot for your help,Anthony
I tweaked the code a little further. When there are more promotors stored, it will add a ',' between each promotor, except the last promotor:
@using umbraco.MacroEngines@inherits umbraco.MacroEngines.DynamicNodeContext<h1>@Model.Name</h1>@if (Model.HasValue("Promotors")){ <p>Promotors: @foreach (var id in @Model.Promotors) { dynamic promotor = new DynamicNode(id.InnerText); if (id.IsLast()) { @promotor.Name } else { @(@promotor.Name + " , "); } } </p>}
This renders something like:
Promotors: John Doe, Jane Doe, Baby Doe
Great!
you can do it little bit nicer like this :
<p>Promotors: @foreach (var id in @Model.Promotors) { dynamic promotor = new DynamicNode(id.InnerText); @promotor.Name if (!id.IsLast()) { @Html.Raw(" , "); } } </p>
but it is same result.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
How to access values stored with MNTP in Razor
Hi,
I'm using uComponents Multi-Node Tree Picker for the first time. I have a custom datatype 'Promotors' that stores promotors:
My Razor-script to render the promotors looks like this:
@if (Model.HasValue("Promotors"))
{
<p>Promotors:
@foreach (var promotor in @Model.Promotors)
{
@promotor.InnerText
}
</p>
}
However, this only renders the id of the stored promotor
How can I render the value of the stored promotor?
Thanks for your help,
Anthony
Hi Anthony.
you have to get the node Object by the id and then you can acsses any property of this node...
Hope that help. cheers.
Hi gilad,
Yes that helps :)
Tweaked my code a little:
@using umbraco.MacroEngines
@inherits umbraco.MacroEngines.DynamicNodeContext
<h1>@Model.Name</h1>
@if (Model.HasValue("Promotors"))
{
<p>Promotors:
@foreach (var id in @Model.Promotors)
{
dynamic promotor = new DynamicNode(id.InnerText);
@promotor.Name
}
</p>
}
This works.
Thanks a lot for your help,
Anthony
I tweaked the code a little further. When there are more promotors stored, it will add a ',' between each promotor, except the last promotor:
@using umbraco.MacroEngines
@inherits umbraco.MacroEngines.DynamicNodeContext
<h1>@Model.Name</h1>
@if (Model.HasValue("Promotors"))
{
<p>Promotors:
@foreach (var id in @Model.Promotors)
{
dynamic promotor = new DynamicNode(id.InnerText);
if (id.IsLast())
{
@promotor.Name
}
else
{
@(@promotor.Name + " , ");
}
}
</p>
}
This renders something like:
Promotors: John Doe, Jane Doe, Baby Doe
Great!
you can do it little bit nicer like this :
<p>Promotors:
@foreach (var id in @Model.Promotors)
{
dynamic promotor = new DynamicNode(id.InnerText);
@promotor.Name
if (!id.IsLast())
{
@Html.Raw(" , ");
}
}
</p>
but it is same result.
is working on a reply...