Copied to clipboard

Flag this post as spam?

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


  • Mitton 22 posts 71 karma points c-trib
    Oct 30, 2014 @ 11:26
    Mitton
    0

    Image cropper on member profile editor

    I want members to be able to edit their pictures, which is a square image cropper.

    I used the profile editor snippet and tried the following, but it does not work:

    @Html.EditorFor(m => profileModel.MemberProperties.Where(p => p.Name == "picture"), "Umbraco.ImageCropper")
    

    I get the error message "Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions."

    Please help?

  • Hywel Rees 56 posts 224 karma points
    Oct 30, 2014 @ 11:34
    Hywel Rees
    0

    Hi,

    This is a .NET error, not an Umbraco issue. It's because you are calling an extension method on MemberProperties.

    http://stackoverflow.com/questions/9925728/templates-can-be-used-only-with-field-access-property-access-single-dimension

     

  • Mitton 22 posts 71 karma points c-trib
    Oct 30, 2014 @ 11:47
    Mitton
    0

    Oh, I see. Thanks Hywel, I didn't realise that.

    I tried adding .First() so that I would only get a single property, not a list, but it's still giving the same error. I'm kind of a noob, so trying to understand that SO article.

    How could I allow a member to edit his picture, which is an image cropper?

  • Mitton 22 posts 71 karma points c-trib
    Oct 30, 2014 @ 11:49
    Mitton
    0

    Oh, I get it now. A member. MemberProperties is a method.

    So will I have to make a new strongly typed model?

  • Hywel Rees 56 posts 224 karma points
    Oct 30, 2014 @ 11:53
    Hywel Rees
    0

    I'm working off the top of my head here but I'd probably assign it to a variable first, so something like:

    @{
    // Rememeber - an exception will be thrown here if there are no items in the
    // model where Name == "picture"
    var item = profileModel.MemberProperties.First(p => p.Name=="picture");
    }

    <!-- some markup -->
    @Html.EditorFor(m => item, "Umbraco.ImageCropper")
  • Mitton 22 posts 71 karma points c-trib
    Oct 30, 2014 @ 11:59
    Mitton
    0

    Ok, I hacked together a little piece of code that makes it compile:

            if (profileModel.MemberProperties[i].Alias == "picture")
            {
                @Html.EditorFor(m => profileModel.MemberProperties[i].Value, "Umbraco.ImageCropper");
            }
    

    But this just gives me the JSON string for the imagecropper.

    These comments are in the profile editor snippet:

            @* 
                By default this will render a textbox but if you want to change the editor template for this property you can 
                easily change it. For example, if you wanted to render a custom editor for this field called "MyEditor" you would
                create a file at ~/Views/Shared/EditorTemplates/MyEditor.cshtml", then you will change the next line of code to 
                render your specific editor template like:
                @Html.EditorFor(m => profileModel.MemberProperties[i].Value, "MyEditor")
            *@
    

    So what do?

  • Mitton 22 posts 71 karma points c-trib
    Oct 30, 2014 @ 12:04
    Mitton
    0

    Maybe the problem is that I assumed I could use the Cropper editor as an editor template.

  • Hywel Rees 56 posts 224 karma points
    Oct 30, 2014 @ 12:15
    Hywel Rees
    0

    Hey,

    I can't really help without seeing more of the code / context etc, but I don't think you need to be using an editor template (this is a sort of partial view), it sounds more like you want to insert the Umbraco Image Cropper itself.

    I'm not familiar with this, so unfortunately can't help :( 

  • Jon Ryan 5 posts 74 karma points
    Aug 09, 2015 @ 12:22
    Jon Ryan
    0

    Did anyone ever figure this out?

    Is it possible to create an editor template that inherits the Image Cropper?

  • Damien (Slipoch) 62 posts 346 karma points
    Aug 11, 2016 @ 03:53
    Damien (Slipoch)
    0

    +1 to this query I am currently trying to do this as well.

Please Sign in or register to post replies

Write your reply to:

Draft