Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have a list of uploaded files in a textarea datatype. I want to split this list, and take the first item in the array...
@foreach (string pic in @node.GetPropertyValue("billeder").ToString().Split(',').Take(1)) { <p>@pic</p> }
Gives me an error... Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Array' does not contain a definition for 'Take'
What to do?
Hi Claus
I think array's don't have the Take method. If you call a ToList() it will probably work
ToList()
@foreach (string pic in @node.GetPropertyValue("billeder").ToString().Split(',').ToList().Take(1)) { <p>@pic</p> }
Dave
Hmmm nope
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Array' does not contain a definition for 'ToList'
I guess you need to add the following using statement to your view
using System.Linq;
But the ToList() is not needed then I think
Now i have:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Somethinsomething> @using ContentModels = Umbraco.Web.PublishedContentModels; @using System.Linq;
in the top of my file - This is not a partial, but a template.
But i still get the error: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Array' does not contain a definition for 'Take'
Hi Claus,
May I ask why you are using the GetPropertyValue syntax ? I see you have models builder enabled.
What type of property is billeder ? And of course what @node is ?
Absolutely, and thank you for taking time to help out.
I am royally confused about Modelsbuilder, so i use what works
@foreach (string pic in @node.Billeder.ToString().Split(','))
works as well
"billeder" is a "Textarea" datatype
@node is the first child from a node picked with MNTP
Do you have it working now ? Or not
Because I tried something similar and didn't even need to include the using statement for system.Linq
Nope, im still getting: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Array' does not contain a definition for 'Take'
when doing:
@foreach (string pic in @node.Billeder.ToString().Split(',').Take(1)) { }
and Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Array' does not contain a definition for 'Tolist'
when doing
@foreach (string pic in @node.Billeder.ToString().Split(',').Tolist().Take(1)) { }
Maybe try to add the following using statement as well
@using System.Collections.Generic;
No difference :I - same errors
Hmmm,
Could what is the output when you don't use the take ?
And what do you get when do : @node.Billeder.ToString().Split(,).GetType().FullName
Without take:
@node.Billeder.ToString().Split(,).GetType().FullName
returns an "argument missing" but
@node.Billeder.ToString().GetType().FullName
return "System.String"
And what does this return
@node.Billeder.ToString().Split(new [] ',').GetType().FullName
Im a bit confused
You just want to know the value of @node.Billeder.ToString().Split(new [] ',').GetType().FullName, right. Not used in a ForEach...
If so, it returns
Compiler Error Message: CS1514: { expected
Hi Claus;
Probably mistyped it. It should be
@node.Billeder.ToString().Split(new [] { ',' }).GetType().FullName
Returns
System.String[]
So we confirmed that it is indeed an array
So now we need to figure out why the Take(1) does not work.
Take(1)
One small step for man... :)
Did some googling and all say is to include a using System.Linq statement
Coud you try this
{ var stringArray = node.Billeder.ToString().Split(','); } @foreach (string pic in System.Linq.Enumerable.Take(stringArray, 1)) { }
Calling the Take extension method directly instead of using as an actual extensions method.
Just to see if it is available.
SUCCESS!
Woohoo !
Still strange the extension method is not picked up when add the using statement.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Split array and take one
I have a list of uploaded files in a textarea datatype. I want to split this list, and take the first item in the array...
Gives me an error... Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Array' does not contain a definition for 'Take'
What to do?
Hi Claus
I think array's don't have the Take method. If you call a
ToList()
it will probably workDave
Hmmm nope
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Array' does not contain a definition for 'ToList'
I guess you need to add the following using statement to your view
But the ToList() is not needed then I think
Dave
Now i have:
in the top of my file - This is not a partial, but a template.
But i still get the error: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Array' does not contain a definition for 'Take'
Hi Claus,
May I ask why you are using the GetPropertyValue syntax ? I see you have models builder enabled.
What type of property is billeder ? And of course what @node is ?
Dave
Absolutely, and thank you for taking time to help out.
I am royally confused about Modelsbuilder, so i use what works
works as well
"billeder" is a "Textarea" datatype
@node is the first child from a node picked with MNTP
Do you have it working now ? Or not
Because I tried something similar and didn't even need to include the using statement for system.Linq
Dave
Nope, im still getting: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Array' does not contain a definition for 'Take'
when doing:
and Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Array' does not contain a definition for 'Tolist'
when doing
Hi Claus,
Maybe try to add the following using statement as well
Dave
No difference :I - same errors
Hmmm,
Could what is the output when you don't use the take ?
And what do you get when do : @node.Billeder.ToString().Split(,).GetType().FullName
Dave
Without take:
returns an "argument missing" but
return "System.String"
And what does this return
Im a bit confused
You just want to know the value of @node.Billeder.ToString().Split(new [] ',').GetType().FullName, right. Not used in a ForEach...
If so, it returns
Hi Claus;
Probably mistyped it. It should be
Dave
Returns
So we confirmed that it is indeed an array
So now we need to figure out why the
Take(1)
does not work.Dave
One small step for man... :)
Hi Claus,
Did some googling and all say is to include a using System.Linq statement
Coud you try this
Calling the Take extension method directly instead of using as an actual extensions method.
Just to see if it is available.
Dave
SUCCESS!
Woohoo !
Still strange the extension method is not picked up when add the using statement.
Dave
is working on a reply...