I have a template that maps to the following Glass model.

[SitecoreType(AutoMap = true)]
public class MyGlassModel
{
    private Link link;

    public virtual Guid Id { get; set; }
    public virtual Link Link
    {
        get { return link; }
        set { link = AddDocumentParameter(value); }
    }

    [SitecoreField("Link text")]
    public virtual string LinkText { get; set; }

    public virtual Guid Document { get; set; }

    private  Link AddDocumentParameter(Link link)
    {
        if (!link.HasValue())
        {
            return link;
        }
        if (link.Query.Contains("doc"))
        {
            return link;
        }
        if (link.Query.Length != 0)
        {
            link.Query += "&";
        }
        link.Query += $"doc={Document}";
        return link;
    }
}

Everything is mapped well, and the doc-parameter is added to the Query property of the Link. Though when I render the link in my view, it's not added.

enter image description here

My view code:

@inherits GlassView<MyGlassModel>
<div class="btn-row">
    @using (BeginRenderLink(cta => cta.Link, isEditable: true, attributes: new { @class = "btn btn-primary" }))
    {
        @Editable(cta => cta.LinkText)
    }
</div>

This is what is being rendered though.
<a class="btn btn-primary scEnabledChrome" href="/nl?test=test" sc-part-of="field">

Why is this, and how can I add the doc-parameter?


Edit: This does seem to work, but not in the Experience Editor.
See <a href="/nl?test=test&doc=e39a4342-a209-423a-be1a-0578ec947dff" class="btn btn-primary">test</a>
I guess my question now is, why does this not work in the Experience editor?

I ran into a similar issue and brought it up with Sitecore Support. According to them there was a bug with the save functionality for links that had querystring parameters. I was provided a patch and have not had an issue since.

From Sitecore support: "When a link with ampersands is saved in Experience Editor, the ampersands in the raw value of the field are not encoded. This causes an error when the Insert Link dialog is opened again for this link (both in Content and Experience Editor)."

They provided reference number 87963 to track this issue but I have not looked into it to see if it's been included in newer releases. I was working with 8.1 update 2 (160302) at the time.

I would reach out to support and reference 87963 to see if they can provide a patch for your version, if it is the same issue.

  • Hi Bill, thank you for responding. Though this isn't really about the value I put in through the experience editor, because that one is showing up correctly. It's about the extra query parameter that I add using code. It works as expected, except for when I'm in editing mode. – sniels Jan 10 '17 at 19:55

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.