Splitting up comma separated value from multiple dropdown in Razor
Total Umbraco noob here and also new to Razor (I'm a frontend and PHP dev).
So I created a document type for one of my pages... App Category. It's a multiple dropdown list where I select all the applicable categories for these applications. If I do this in my view...
@Umbraco.Field("appCategory")
I get...
Small Business Apps,Accounting Apps,Franchise Apps,Non-profit Apps
What is the proper way to create an array from this comma separated list that I can then use in a foreach? Sorry... again... total noob to .Net and I'm confused.
You need to use a little bit more code, and there a multiple options for place your code. You could place it directly into your template, our you could create a partial view or partial view macro.
You are always welcome to write on the forum, too. We are friendly people. who try to help each other. So if you have other questions just create a topic on the forum.
Thanks guys, I do need to just find my way around the info. I actually bought a year long membership to umbraco.tv.
My syntax was off using Split() but I was in the ball park. I really appreciate the help... I kind of went into this kicking and screaming but I actually am start to really like working with this. I think my issue is more getting around Razor. I got the site completely scaffolded... now I just dealing with random issues.
If its a Multi Node Tree Picker. You are better creating some complied code that takes in your IPublishedContent, does the split and return you a enumeration of the individual strings.
I'm having a bit of trouble with splitting a string at a comma.
I get the correct string from the api (Mon,Wed,Fri,Sun) but when I try to split it and foreach the days the macro crashes and the logs give a CS1513 error.
Does anyone have a solution for this as I can't seem to find any.
Don´t know if the can be the problem, but could you try the code below. I have removed the @ before in the variable called categories because you are already in the Razor context.
Splitting up comma separated value from multiple dropdown in Razor
Total Umbraco noob here and also new to Razor (I'm a frontend and PHP dev).
So I created a document type for one of my pages... App Category. It's a multiple dropdown list where I select all the applicable categories for these applications. If I do this in my view...
I get...
Small Business Apps,Accounting Apps,Franchise Apps,Non-profit Apps
What is the proper way to create an array from this comma separated list that I can then use in a foreach? Sorry... again... total noob to .Net and I'm confused.
Hi Greg and welcome to our,
You need to use a little bit more code, and there a multiple options for place your code. You could place it directly into your template, our you could create a partial view or partial view macro.
The documentation for the dropdown list multiple, publish keys can you find here: http://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/built-in-property-editors-v7/DropDown-List-Multiple-Publish-Keys or the dropdown list multiple http://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/built-in-property-editors-v7/DropDown-List-Multiple
And since your are new to Umbraco I think that you should have a look at Umbraco TV, this is video tutourials about Umbraco, and there are some free videos about the basic concepts of Umbraco http://umbraco.tv/videos/umbraco-v7/content-editor/ and http://umbraco.tv/videos/umbraco-v7/implementor/. One of the milestones in Umbraco is the concept called Document types, here you define fields for the user in the backoffice. http://umbraco.tv/videos/umbraco-v7/implementor/fundamentals/document-types/what-is-a-document-type/
Some of the videos are requiring a subscription to Umbraco TV, and you can find the prices here. http://umbraco.tv/plans-signup/
Another good starting point would be http://our.umbraco.org/documentation/Using-Umbraco/Creating-Basic-Site/
You are always welcome to write on the forum, too. We are friendly people. who try to help each other. So if you have other questions just create a topic on the forum.
Hope this helps,
/Dennis
Hi Greg,
Great direction from Dennis for best practices.
"What is the proper way to create an array from this comma separated list that I can then use in a foreach?" - here's one way..
Thanks guys, I do need to just find my way around the info. I actually bought a year long membership to umbraco.tv.
My syntax was off using Split() but I was in the ball park. I really appreciate the help... I kind of went into this kicking and screaming but I actually am start to really like working with this. I think my issue is more getting around Razor. I got the site completely scaffolded... now I just dealing with random issues.
Greg what property type is appCategory?
If its a Multi Node Tree Picker. You are better creating some complied code that takes in your IPublishedContent, does the split and return you a enumeration of the individual strings.
Charlie :)
Hey folks
I'm having a bit of trouble with splitting a string at a comma. I get the correct string from the api (Mon,Wed,Fri,Sun) but when I try to split it and foreach the days the macro crashes and the logs give a CS1513 error.
Does anyone have a solution for this as I can't seem to find any.
Here's my code.
Btw I've also tried to have a string[] instead of var in categories and in category . So that's not the issue
Hi Gisli,
Don´t know if the can be the problem, but could you try the code below. I have removed the @ before in the variable called categories because you are already in the Razor context.
Hope this helps,
/Dennis
thanks for the reply Dennis but my problem was the " in Split(",") apparently I have to use ' instead to get it to work for me..
Thanks
is working on a reply...