Copied to clipboard

Flag this post as spam?

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


  • Decneo 8 posts 78 karma points
    Nov 11, 2019 @ 14:51
    Decneo
    0

    'IEnumerable<Link>' does not contain a definition for 'Target' and no accessible extension method 'Target'

    Hello,

    My local site works fine until I transfer content and media from local to the cloud after finished I came back to check the local site again but I got this error.

    enter image description here

  • Jonathan Distenfeld 105 posts 618 karma points
    Nov 11, 2019 @ 14:58
    Jonathan Distenfeld
    0

    Hi Decneo,

    what PropertyType does your "Link"-Property have?

    ~ Jonathan

  • Decneo 8 posts 78 karma points
    Nov 11, 2019 @ 15:49
    Decneo
    0

    Hi Jonathan,

    they're data type

    enter image description here

  • Rob Shaw 24 posts 147 karma points
    Nov 11, 2019 @ 16:25
    Rob Shaw
    0

    It looks like you are trying to access a property (Target, Url) of a Link class from a collection of Link types.

    You should iterate through each of the Link types in the collection via a foreach loop like this:

    @if (Model.Link.Any())
    {
      foreach (var link in Model.Link)
      {
        <a target="@link.Target" href="@link.Url">@link.Icon</a>
      }
    }
    
  • Decneo 8 posts 78 karma points
    Nov 12, 2019 @ 03:18
    Decneo
    0

    Thank you Rob Shaw for your idea. actually I am not a developer who created this template, but I would like to figure this out while waiting for the developer's response.

    This is the original file.

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.A04Hyperlink>
    @using ContentModels = Umbraco.Web.PublishedModels;
    @{
        var cssTheme = Model.Theme?.ToLower();
        var cssStyle = Model.Style ? "underline":"wo-underline";
        var cssInverse = Model.Inverse ? "inverse" : "";
        var cssIcon = Model.Icon?.ToLower().Replace(" ","-");
    }
    
    @if (Model.Link != null)
    {
    <a data-atom="hyperlink" target="@Model.Link.Target" href="@Model.Link.Url" class="hyperlink @cssTheme @cssStyle @cssInverse ">
        @if (Model.Icon != null)
        {
            <i data-atom="hyperlink-icon" class="icon-@cssIcon"></i>
        }
        <span data-atom="hyperlink-title">@Model.Link.Name</span>
    </a>
    }
    

    This is after your suggestion

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.A04Hyperlink>
    @using ContentModels = Umbraco.Web.PublishedModels;
    @{
        var cssTheme = Model.Theme?.ToLower();
        var cssStyle = Model.Style ? "underline":"wo-underline";
        var cssInverse = Model.Inverse ? "inverse" : "";
        var cssIcon = Model.Icon?.ToLower().Replace(" ","-");
    }
    
    @if (Model.Link.Any())
    {
      foreach (var link in Model.Link)
      {
        <a target="@link.Target" href="@link.Url">@link.Icon</a>
      }
    }
    

    after refresh the site I got this error. enter image description here

    I really appreciated your help.

  • Jonathan Distenfeld 105 posts 618 karma points
    Nov 12, 2019 @ 07:12
    Jonathan Distenfeld
    1

    Hi Decneo,

    The link.Icon was just an example. You will have to change it to following:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.A04Hyperlink>
    @using ContentModels = Umbraco.Web.PublishedModels;
    @{
        var cssTheme = Model.Theme?.ToLower();
        var cssStyle = Model.Style ? "underline":"wo-underline";
        var cssInverse = Model.Inverse ? "inverse" : "";
        var cssIcon = Model.Icon?.ToLower().Replace(" ","-");
    }
    
    @if (Model.Link != null && Model.Link.Any())
    {
        foreach (var link in Model.Link)
        {
            <a data-atom="hyperlink" target="@link.Target" href="@link.Url" class="hyperlink @cssTheme @cssStyle @cssInverse ">
                @if (Model.Icon != null)
                {
                    <i data-atom="hyperlink-icon" class="icon-@cssIcon"></i>
                }
                <span data-atom="hyperlink-title">@link.Name</span>
            </a>
        }
    }
    

    Of course you have to change things to your needs. But it should clarify the problem.

    ~ Jonathan

  • Decneo 8 posts 78 karma points
    Nov 12, 2019 @ 07:50
    Decneo
    0

    Dear Jonathan, It is working now with your codes :D, you save my day, thank you very much. :D

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies