Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Roger Withnell 128 posts 613 karma points
    Mar 03, 2016 @ 19:41
    Roger Withnell
    0

    Display an image in an MVC partial view

    I can display an image with the code in a partial macro as follows:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{
        var vkindEventsParentPageId = Model.MacroParameters["kindEventsParentPage"];
        //var vkindEventsFilter = Model.MacroParameters["kindEventsFilter"];
    
    
        var vHomeNode = Model.Content.AncestorOrSelf(2);
        var vParentPageNode = vHomeNode;
        vParentPageNode = Umbraco.Content(vkindEventsParentPageId);
    
        int vCtr = 0;
        foreach (var vEventItem in vParentPageNode.Children)
        {
            if (vCtr == 0)
            {
                @:<div class="row clearfix">
            }
            <div class="col-md-4 column">
                <div class="panel panel-default">
                    @{
            if (vEventItem.HasValue("logo", true))
            {
                var mediaItem = Umbraco.TypedMedia(vEventItem.GetPropertyValue("logo", true));
                <div class="panel-heading">
                    <div class="panel-title">
                        <div style="float:left; width:25%">
                            <img src="@mediaItem.GetPropertyValue("umbracoFile")" alt="@mediaItem.GetPropertyValue("Name")" />
                        </div>
    

    This works fine. But if I use similar code in a Partial View "Umbraco.TypedMedia is not available:

    @model UmbracoWebsites.Models.kindEvents
    
    @using System;
    @using System.Data;
    
    @{
        int vCtr = 0;
        foreach (DataRowView vRow in Model.kindEventsView)
        {
            dynamic vEventNode = vRow["EventNode"];
            if (vCtr == 0)
            {
                @:<div class="row clearfix">
    
    
            }
            <div class="col-md-4 column">
                <div class="panel panel-default">
                    @{
            if (vEventNode.HasValue("logo", true))
            {
                var mediaItem = Umbraco.TypedMedia(vEventNode.GetPropertyValue("logo", true));
                <div class="panel-heading">
                    <div class="panel-title">
                        <div style="float:left; width:25%">
                            <img src="@mediaItem.GetPropertyValue("umbracoFile")" alt="@mediaItem.GetPropertyValue("Name")" />
                        </div>
    

    What am I doing wrong?

    Your help would be much appreciated.

    Thanking you in anticipation.

    Roger

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Mar 03, 2016 @ 20:36
    Steve Morgan
    100

    Try changing your first line to

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<UmbracoWebsites.Models.kindEvents>
    

    From the section Strongly typed Partial Views https://our.umbraco.org/documentation/Reference/Templating/Mvc/partial-views

    That should give you access to the Umbraco helper etc.

    Hth

    Steve

Please Sign in or register to post replies

Write your reply to:

Draft