I'm very new to razor and struggling with something.
I have a partial view which outputs related links in the left nav, I'm trying to do the same thing with related media e.g. pdf's that I've selected with the multiple media picker. This is the code for the links list:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@*
Related Items / Links / Pages
*@
@{
if ( Model.Content.HasValue("relatedItems") )
{
if ( CurrentPage.relatedItems.Count > 0 )
{
<div class="related-items">
<div class="page-header">
<h2>@umbraco.library.GetDictionaryItem("Related")</h2>
</div>
<ul class="nav nav-list">
@foreach(var link in CurrentPage.relatedItems)
{
<li>
@{
var linkTarget = link.newwindow == "1" ? "target=\"_blank\"" : "";
}
<a href="@link.link" @Html.Raw(linkTarget)>@link.title</a>
</li>
}
</ul>
</div>
}
}
}
Can anybody help with this and also suggest where I can find some good reference material to learn Razor? Not having intellisense and syntax checking in the back office is a real pain :(
@{
var media = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("relatedItems");
if (media.Any())
{
foreach (var item in media)
{
<a href="@item.Url" target="_blank">@item.Name</a>
}
}
}
While of course I would agree with Dan that my package makes this super simple you can also do it without and there is a code snippet in the documention here
Also if you want intellisence you can used the typed model (Model.Content) and Visual Studio Express or WebMatrix to edit your Views/Partials/Etc
Listing media items
Hi,
I'm very new to razor and struggling with something.
I have a partial view which outputs related links in the left nav, I'm trying to do the same thing with related media e.g. pdf's that I've selected with the multiple media picker. This is the code for the links list:
Can anybody help with this and also suggest where I can find some good reference material to learn Razor? Not having intellisense and syntax checking in the back office is a real pain :(
Thanks
Rich
Hi Rich,
If you install Jeavon Leopold's Umbraco Core Property Value Converters package and follow his documentation, you'll be able to write something like the following:
Thanks, Dan.
Hi Rich,
While of course I would agree with Dan that my package makes this super simple you can also do it without and there is a code snippet in the documention here
Also if you want intellisence you can used the typed model (Model.Content) and Visual Studio Express or WebMatrix to edit your Views/Partials/Etc
Jeavon
Thank you Dan and Jeavon.
I have re worked the code as per the example but it doesn't appear to be rendering?
Hi Richard,
Please try,
Thanks Jeavon that works a treat :)
is working on a reply...