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)
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?
@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;}
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.
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
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.
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.
@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>
}
}
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
Exception Details: System.InvalidOperationException: The value Umbraco.Core.Models.Editors.ContentPropertyData cannot be converted to the type Integer
Stack Trace:
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
Great thx.
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:
Jeavon
Ok, so basically I get a int array, joined bij comma. Thanks for the info.
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:
There must be some one know this problem.
Hi Julie,
You can use the above workaround for v7.0.0. The issue is being looked at.
Jeavon
Thanks, very useful!
Cheers!
Glad it was useful to you :-)
Of course you should upgrade to v7.0.1 where the issue is resolved anyway
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?
Hi Jeff,
Welcome to Our, could you please post the entire contents of your View .cshtml Razor file?
Thanks,
Jeavon
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.
Do you have an inherits line at the very top of the file? e.g
@inherits umbraco.MacroEngines.DynamicNodeContext
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
/Macroscripts/Mycode.html
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.
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.
Hi Jeff,
Please try the below, replace "caseStudyImages" with the alias of your media picker property alias
Jeavon
Still blank when making that change.
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
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?
old topic but i think this is a better solution:
public class MediaPicker { public List
JsonConvert.DeserializeObject
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.
is working on a reply...