Copied to clipboard

Flag this post as spam?

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


  • André Steenbergen 23 posts 43 karma points
    Nov 19, 2013 @ 22:14
    André Steenbergen
    0

    How to use the media picker in umbraco 7

    I am using the mediapicker in on of the documenttypes foto album. I can select multiple files. But when I @Model.Content.GetPropertyValue("fotos") I just get 1 Id. Is it possible to get all images associated with the property?

    I can;t seem to test this locally, because locally I can only story 1 item, when mulitple items are selected I get this error, anyone seen this before?

    The value Umbraco.Core.Models.Editors.ContentPropertyData cannot be converted to the type Integer

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.InvalidOperationException: The value Umbraco.Core.Models.Editors.ContentPropertyData cannot be converted to the type Integer 

    Stack Trace: 

    bij Umbraco.Core.PropertyEditors.PropertyValueEditor.ConvertEditorToDb(ContentPropertyData editorValue, Object currentValue)
       bij Umbraco.Web.Editors.ContentControllerBase.MapPropertyValues[TPersisted](ContentBaseItemSave`1 contentItem)
       bij Umbraco.Web.Editors.ContentController.MapPropertyValues(ContentItemSave contentItem)
       bij Umbraco.Web.Editors.ContentController.PostSave(ContentItemSave contentItem)
       bij lambda_method(Closure , Object , Object[] )
       bij System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)
       bij System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
       bij System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4()
       bij System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Nov 20, 2013 @ 08:46
    Jeavon Leopold
    0

    Hi André,

    Yes and this issue has been fixed. You can get a nightly build from http://nightly.umbraco.org/umbraco%207.0.0/ or wait for the next release tomorrow.

    Jeavon

  • André Steenbergen 23 posts 43 karma points
    Nov 20, 2013 @ 11:16
    André Steenbergen
    0

    Great thx.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Nov 20, 2013 @ 21:07
    Jeavon Leopold
    0

    Hi André,

    I have checked this with build 175 today and it works fine, this is the test razor is used to output multiple images:

    @if (Model.Content.HasValue("caseStudyImage"))
    {
        var caseStudyImagesList = Model.Content.GetPropertyValue<string>("caseStudyImage").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
        var caseStudyImagesCollection = Umbraco.TypedMedia(caseStudyImagesList).Where(x => x != null);
    
        foreach (var caseStudyImage in caseStudyImagesCollection)
            {      
                <img src="@caseStudyImage.Url" />      
            }                                                               
    }
    

    Jeavon

  • André Steenbergen 23 posts 43 karma points
    Nov 20, 2013 @ 23:23
    André Steenbergen
    0

    Ok, so basically I get a int array, joined bij comma. Thanks for the info.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Nov 22, 2013 @ 20:27
    Jeavon Leopold
    0

    Yes, I actually discovered a bug in the UmbracoHelper if a media item has been deleted, so my code had to change until there is a fix:

    @if (Model.Content.HasValue("caseStudyImage"))
    {
        var caseStudyImagesList = Model.Content.GetPropertyValue<string>("caseStudyImage").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);  
    
        foreach (var item in caseStudyImagesList)
        {
            // Try/Catch workaround for Umbrco.TypedMedia throwing an exception if media item has been deleted. http://issues.umbraco.org/issue/U4-3630        
            IPublishedContent image;
            try { image = Umbraco.TypedMedia(item); }
            catch { image = null; }
    
            if (image != null)
            {
                <img src="@image.Url" />
            }
        }
    }
    
  • Julie 3 posts 22 karma points
    Nov 28, 2013 @ 09:14
    Julie
    0

    There must be some one know this problem.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Nov 28, 2013 @ 09:19
    Jeavon Leopold
    0

    Hi Julie,

    You can use the above workaround for v7.0.0. The issue is being looked at.

    Jeavon

  • Gui Andrade Coutinho 5 posts 25 karma points
    Dec 30, 2013 @ 10:06
    Gui Andrade Coutinho
    0

    Thanks, very useful!

    Cheers!

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Dec 30, 2013 @ 20:59
    Jeavon Leopold
    0

    Glad it was useful to you :-)

    Of course you should upgrade to v7.0.1 where the issue is resolved anyway

  • jeff mayer 122 posts 200 karma points
    Jan 13, 2014 @ 21:28
    jeff mayer
    0

    Running default 7.01 Install but getting this error with with both code blocks listed above:

     

    Saving scripting file failed: d:\inetpub\labcf\MacroScripts\635252223640135785_ListDocs.cshtml(14): error CS1976: Cannot use 'Parse' as an argument to a dynamically dispatched operation because it is a method group. Did you intend to invoke the method?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 13, 2014 @ 21:47
    Jeavon Leopold
    0

    Hi Jeff,

    Welcome to Our, could you please post the entire contents of your View .cshtml Razor file?

    Thanks,

    Jeavon

  • jeff mayer 122 posts 200 karma points
    Jan 14, 2014 @ 13:51
    jeff mayer
    0

    Thanks Jeavon, same code as used in example


    @if(Model.Content.HasValue("docfile"))
    {
       
    var caseStudyImagesList =Model.Content.GetPropertyValue<string>("docfile").Split(newstring[]{","},StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);  

       
    foreach(var item in caseStudyImagesList)
       
    {
           
    // Try/Catch workaround for Umbrco.TypedMedia throwing an exception if media item has been deleted. http://issues.umbraco.org/issue/U4-3630        
           
    IPublishedContent image;
           
    try{ image =Umbraco.TypedMedia(item);}
           
    catch{ image =null;}

           
    if(image !=null)
           
    {
               
    <img src="@image.Url"/>
           
    }
       
    }
    }
  • André Steenbergen 23 posts 43 karma points
    Jan 14, 2014 @ 13:54
    André Steenbergen
    0

    What do you get when you only place Model.Content.GetPropertyValue<string>("docfile") in you code? It should provide you with a string representation of an integer array. If that is not the case, the int.Parse part will throw an error.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 14, 2014 @ 14:01
    Jeavon Leopold
    0

    Do you have an inherits line at the very top of the file? e.g

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
  • jeff mayer 122 posts 200 karma points
    Jan 14, 2014 @ 15:06
    jeff mayer
    0

    @inherits umbraco.MacroEngines.DynamicNodeContext

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 14, 2014 @ 15:34
    Jeavon Leopold
    0

    Ah ok Jeff, that explains it. This sample is to be used in a View, Partial View or a Macro Partial View or a Legacy Razor Macro (which it seems you might be using).

    In Umbraco v7, legacy Razor Macros (MacroScripts Folder) are for legacy support only. If you are using MVC templating then you can use Views and Partial Views, if you use MasterPage templates then you can use Macro Partial Views.

    Where is your .cshtml file located, e.g. /MacroScripts/MyCode.cshtml or /Views/MacroPartials/MyCode.cshtml

    Jeavon

  • jeff mayer 122 posts 200 karma points
    Jan 14, 2014 @ 15:40
    jeff mayer
    0

    /Macroscripts/Mycode.html

     


  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 14, 2014 @ 15:52
    Jeavon Leopold
    0

    Ok, if you are using MasterPage templates, then try creating a Macro Partial View instead (it will be created in /Views/MacroPartials/MyCode.cshtml) However, if you are starting with a clean Umbraco v7, then I would recommend you use MVC templates then this code can go directly into your template (View) rather than MasterPages.

  • jeff mayer 122 posts 200 karma points
    Jan 14, 2014 @ 17:44
    jeff mayer
    0

    Thank you for the clarification. Was using webforms and macroscripts with v6 and 4.  When I convert to a partial view macro  the code does not error out, but its not displaying any output. In my case I am using PDF documents not images, but I assumed it would still generate some kind of output on the page. I'll modify the code to be a link , but I wanted to make sure the code was outputting something. 

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 14, 2014 @ 17:54
    Jeavon Leopold
    2

    Hi Jeff,

    Please try the below, replace "caseStudyImages" with the alias of your media picker property alias

    @if (Model.Content.HasValue("caseStudyImages"))
    {
        var caseStudyImagesList = Model.Content.GetPropertyValue<string>("caseStudyImages").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
        var caseStudyImagesCollection = Umbraco.TypedMedia(caseStudyImagesList).Where(x => x != null);
    
        foreach (var caseStudyImage in caseStudyImagesCollection)
            {           
                <a href="@caseStudyImage.Url">@caseStudyImage.Name</a>
            }                                                               
    }
    

    Jeavon

  • jeff mayer 122 posts 200 karma points
    Jan 14, 2014 @ 21:05
    jeff mayer
    0

    Still blank when making that change. 

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 15, 2014 @ 08:33
    Jeavon Leopold
    0

    Hi Jeff, could you please post some screenshots or a screenr showing all your important areas, e.g. Content editor, document type, template etc?

    Jeavon

  • Chris 9 posts 29 karma points
    Feb 12, 2014 @ 17:00
    Chris
    0

    Why is it so tricky to use the media picker? why not have a script that  on the template under insert page field there is a media picker option?

     

  • Edwin van Koppen 156 posts 270 karma points
    Feb 14, 2014 @ 13:06
    Edwin van Koppen
    0

    old topic but i think this is a better solution:

    public class MediaPicker { public List

    JsonConvert.DeserializeObject

  • Chris 9 posts 29 karma points
    Feb 14, 2014 @ 13:29
    Chris
    0

    I found out the problem. I was using Firefox 20.0.1 and what ever chages I did and saved but when i browsed to the page there was nothing.

    Today when I logged in al the chnges I had saved were gone so i tried chrome and added the following to the template it worked fine.

     

    <umbraco:Macro runat="server" language="cshtml">
                    <img src="@Model.MediaById(Model.bottonLeftSmall).umbracoFile" alt="bottom left smiling"/>
                </umbraco:Macro>   

     

    (I am working on Azzure as well) hope this helps someone out there as well.

  • Guy Pucill 23 posts 73 karma points
    May 06, 2014 @ 01:11
    Guy Pucill
    0
        @inherits umbraco.MacroEngines.DynamicNodeContext
    
        @* I am working in 7.1.1. This give me nice media ID list like 1115,1114,1116 *@
        @if(Html.Raw(Parameter.ListeAlias) != null)
        {
            @(Html.Raw(Parameter.ListeAlias))
        }
    
    @* how do i split them up? and why is my If line not working? *@
    @if(Model.HasValue("ListeAlias"))
    {
        foreach (var item in Model.GetProperty("ListeAlias").Value.Split(','))
        {
            <p>@Model.MediaById(@item).umbracoFilegg</p>
            <p>Testing IF clause</p>
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft