I'm a newbie on Umbraco and on HTML, i'm developing a simple website for my music band :). I'm using Link Picker and it works well. But i need to use it also inside Archetype Model, and i don't understand why it doesn't work.
@foreach (var fieldset in Model.Content.GetPropertyValue<Archetype.Models.ArchetypeModel>("Categorie"))
{
var a = fieldset.GetValue("link");
<a href="@a.Url">
Hi Jan. Thank you for your quickly reply. I hope that the full code of the pages will be helpfull. If i use @a.Url it give me an Server Error in '/' Application (???). I have tryed to print @a. The result (It seems ok):
When you have included Archetype Model namespace you have access to strongly typed model.
But as a remember Link Picker doesn't include an assembly by default - you have to add you own class to get strongly typed model like in the example in readme.
Did you try writing "url" starting with a lowercase "u"?
Otherwise you can create a class for LinkPicker model like in the readme and either include in a namespace and compile it, or add the class file in App_Code folder to compile it at runtime.
In that case you can use:
var b = JsonConvert.DeserializeObject<LinkPickerModel>(a.ToString());
<a href="@b.Url">@b.Name</a>
Link Picker on Archetype
Hi.
I'm a newbie on Umbraco and on HTML, i'm developing a simple website for my music band :). I'm using Link Picker and it works well. But i need to use it also inside Archetype Model, and i don't understand why it doesn't work.
Please help me. Best Reguards. AB
Hi Andrea and welcome to the forums! :)
When you render the code above does it then give you any kind of error or does the @a.url just not render anything in your code?
Is it also possible that you perhaps can post a screendump of what your setup on the content node where you select the link in Umbraco looks like?
Looking forward to hearing from you.
/Jan
Hi Jan. Thank you for your quickly reply. I hope that the full code of the pages will be helpfull. If i use @a.Url it give me an Server Error in '/' Application (???). I have tryed to print @a. The result (It seems ok):
Thank you so much! AB
up
Somebody that can help me please! ðŸ˜
Hi Andrea
I think you can access the values if you type it in camelCase.. E.g.
@a.url
Or use Newstonsoft.Json to deserialize the json and you can add a class for the model like here https://github.com/Gibe/Umbraco-Link-Picker/blob/master/README.md
When you have included Archetype Model namespace you have access to strongly typed model. But as a remember Link Picker doesn't include an assembly by default - you have to add you own class to get strongly typed model like in the example in readme.
/Bjarne
Thank you Bjarne for your support. I've tryed to use Json deserialize but i think that how i have done isn't correct.. :(..
It doesn't work (server error in application). What is it the problem? Thanks so much.
Hi Andrea
"a" is already the json string, so you need to deserialize that.. So remove "value" (that was just an example of a variable containing json.
So something like this:
I am not sure if you can use @b.Url without creating a class for the model, which has a property "Url".
/Bjarne
Hi,
please check that "a" is not null & a.value is not null
Thanks
I have tried what Bjarne you have written:
var a = fieldset.GetValue("link"); var b = JsonConvert.DeserializeObject(a.ToString());
@a have this values:
{ "id": "1113", "name": "Prova", "url": "/Band/Prova/", "target": "_self", "hashtarget": "" }
i have to try to use @b.Url but it dosen't work (the same server error). @b have the samevalues of @a.
how can i create the class "Url"?
Sorry men but i'm a newbie on Umbraco, Html, CSS, and on programming :'(
Thanks so much.
Did you try writing "url" starting with a lowercase "u"?
Otherwise you can create a class for LinkPicker model like in the readme and either include in a namespace and compile it, or add the class file in App_Code folder to compile it at runtime.
In that case you can use:
/Bjarne
Ok. It works. Thanks to everyone.
I am glad it solved your issue Andrea :)
/Bjarne
is working on a reply...