Copied to clipboard

Flag this post as spam?

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


  • Keith R Hubbard 175 posts 403 karma points
    Jun 21, 2017 @ 15:28
    Keith R Hubbard
    0

    Text over image Editor [email protected]

    I am getting this error with the partial

    Error loading TextoverImagePartial

    Has anyone else run into this?

        @model TextOverImage.Models.ImageWithText
    @{
    
        // Use this code to render this partial in your template. Replace "banner" with whatever your property name is
        // Make sure to include @using TextOverImage.Models at the top of your template
        //@if(Model.Content.HasProperty("banner") && Model.Content.HasValue("banner"))
        //{
        //    @Html.Partial("TextOverImagePartial", Model.Content.GetPropertyValue<ImageWithText>("banner")
        //}
    
        // You could use banner.Media.GetCropUrl(width,height) here instead if you want to set it!
        var imageUrl = Model.Media != null ? Model.Media.Url : string.Empty;
    
        // Only render the style tag if the image url exists
        var style = !string.IsNullOrEmpty(imageUrl) ? MvcHtmlString.Create(" style=\"background: url(" + imageUrl + ") no-repeat center center; background-size: cover;\"") : MvcHtmlString.Empty;
    }
    <div class="banner [email protected]"@style>
        <div class="banner--inner [email protected]">
            <h1>@Model.Headline</h1>
            <h2>@Model.Subheadline</h2>
            @if (Model.Link != null)
            {
                <a href="@Model.Link.Url" target="@Model.Link.Target" class="button">@Model.Link.Name</a>
            }
        </div>
    </div>
    
  • Nicholas Westby 2054 posts 7104 karma points c-trib
    Jun 21, 2017 @ 15:35
    Nicholas Westby
    1

    You have not passed a model in when you rendered the partial:

    @Html.Partial("TextOverImagePartial")
    

    The code you pasted actually shows what you should be doing:

    @Html.Partial("TextOverImagePartial", Model.Content.GetPropertyValue<ImageWithText>("banner"))
    

    Although it was missing a closing paren (which I added).

    When you do not specify a model, the model for the parent context gets used, which will not work in this case. I think passing null has the same effect.

  • Keith R Hubbard 175 posts 403 karma points
    Jun 21, 2017 @ 15:58
    Keith R Hubbard
    0

    I think this is called read the code!!!

  • 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