Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Andrea 7 posts 87 karma points
    May 11, 2016 @ 16:33
    Andrea
    0

    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.

    @foreach (var fieldset in Model.Content.GetPropertyValue<Archetype.Models.ArchetypeModel>("Categorie"))
    {
    
    var a = fieldset.GetValue("link");
    <a href="@a.Url">
    

    Please help me. Best Reguards. AB

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 11, 2016 @ 19:37
    Jan Skovgaard
    1

    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

  • Andrea 7 posts 87 karma points
    May 12, 2016 @ 06:45
    Andrea
    0
    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using Archetype.Models;
    @using Archetype.Extensions;
    @using Newtonsoft.Json;
    
    @{
        Layout = "Monoblocco.cshtml";
    }
    
    <div class="Hero">
    <div class="container">
    <div class="row">
    <div class="col-sm-8 col-sm-offset-4 col-md-8 col-md-offset-4 col-lg-8 col-lg-offset-4 col-xs-12 text-right"><h3 class="titolo">@Umbraco.Field("titolo")</h3></div>
    </div>
    </div>
    </div>
    <div class="container">
    @foreach (var fieldset in Model.Content.GetPropertyValue<Archetype.Models.ArchetypeModel>("Categorie"))
    {
    
    var a = fieldset.GetValue("link");
    <a href="@a.Url">
    <div class="row principale riquadrocategorie">
    <div class="col-sm-3 col-md-3 col-lg-3 col-xs-12"><img class="img-responsive center-block imgcategorie" src="@(Umbraco.TypedMedia(fieldset.GetValue("immagine")).Url)" alt="@fieldset.GetValue("titolo")"/></div>
    <div class="col-sm-9 col-md-9 col-lg-9 col-xs-12"><h3 class="text-left">@fieldset.GetValue("titolo")</h3><h4 class="text-left">@fieldset.GetValue("descrizione")</h4><h4 class="text-left"><strong>Caratteristiche:</strong> @fieldset.GetValue("Caratteristiche")</h4></div>
    </div>
    </a>
    }
    </div>
    

    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):

    { "id": "1113", "name": "Prova", "url": "/Band/Prova/", "target": "_self", "hashtarget": "" }

    Thank you so much! AB

  • Andrea 7 posts 87 karma points
    May 13, 2016 @ 12:13
    Andrea
    0

    up

  • Andrea 7 posts 87 karma points
    May 14, 2016 @ 11:07
    Andrea
    0

    Somebody that can help me please! 😭

  • Bjarne Fyrstenborg 1286 posts 4060 karma points MVP 8x c-trib
    May 14, 2016 @ 12:12
    Bjarne Fyrstenborg
    0

    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

  • Andrea 7 posts 87 karma points
    May 16, 2016 @ 07:22
    Andrea
    0

    Thank you Bjarne for your support. I've tryed to use Json deserialize but i think that how i have done isn't correct.. :(..

    var a = fieldset.GetValue("link");
    var b = JsonConvert.DeserializeObject(a.value.ToString());
    var c = b.Url;
    
    <a href="@c">
    

    It doesn't work (server error in application). What is it the problem? Thanks so much.

  • Bjarne Fyrstenborg 1286 posts 4060 karma points MVP 8x c-trib
    May 16, 2016 @ 08:36
    Bjarne Fyrstenborg
    0

    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:

    var a = fieldset.GetValue("link");
    var b = JsonConvert.DeserializeObject(a.ToString());
    
    <a href="@b.url">@b.name</a>
    

    I am not sure if you can use @b.Url without creating a class for the model, which has a property "Url".

    /Bjarne

  • Michael 125 posts 409 karma points
    May 16, 2016 @ 08:27
    Michael
    0

    Hi,

    please check that "a" is not null & a.value is not null

    Thanks

  • Andrea 7 posts 87 karma points
    May 16, 2016 @ 09:50
    Andrea
    0

    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.

  • Bjarne Fyrstenborg 1286 posts 4060 karma points MVP 8x c-trib
    May 16, 2016 @ 11:04
    Bjarne Fyrstenborg
    100

    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>
    

    /Bjarne

  • Andrea 7 posts 87 karma points
    May 16, 2016 @ 12:20
    Andrea
    0

    Ok. It works. Thanks to everyone.

  • Bjarne Fyrstenborg 1286 posts 4060 karma points MVP 8x c-trib
    May 16, 2016 @ 12:35
    Bjarne Fyrstenborg
    0

    I am glad it solved your issue Andrea :)

    /Bjarne

Please Sign in or register to post replies

Write your reply to:

Draft