Mindless Philosophy






Get data from uComponents Multi-URL Picker

by Darren Street

Created on: Friday February 28, 2014

1 comments

There are a dozen search pages about the uComponents Multi-URL Picker and trying to get any data out of it. Many people have been pulling their hair out trying to get it to work. Well after much hair pulling I figured the correct syntax for anyone using Umbraco 4.11.x and uComponents V5.5.4.

urlpicker

Remember the syntax is different for V6.x MVC sites.

So you have installed the uComponents package and have created a data type.

Ensure that you have the Data Format set to XML. You can use CSV but you will need to split the string and it’s a faff.

Remember the name of the Data Type, for reference ours is called “refreshRelatedContent”. Go ahead and create your document types and assign a new control to the new Data Type you have just created.

Now create a new Razor Scripting File (or inline script) and insert the following code:

Urlpicker-code

I have stripped most stuff out so it’s easy to see what is going on.

The foreach is creating a variable called "pageURL" and assigning it the value of the control

Model._refreshRelatedContent (your new doc type alias).

As this control is a collection you need to iterate through it with the foreach. The important bit that was missed on many posting is the “.Items” which exposes the individual URLs bound to the control.

If you omit this you get a type mismatch. Something like “cannot convert urlpicker to ienumerable”

So you have the reference to the control, just list it out in an anchor .Url shows the url path .Title shows the optional link title. Note that if you don’t insert a title in your control, your link won’t show up either.

That’s it. It’s the bare bones that should get you going. I would however test for null first, and put some conditional code in the href to test for target_blank

1 comments




Richard Stywick commented on 7 Mar 2014


Thanks for the tut. It helped me out



Have your say


Sorry this post is no longer accepting comments.