Copied to clipboard

Flag this post as spam?

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


  • Palle Hansen 143 posts 396 karma points
    Feb 26, 2017 @ 09:44
    Palle Hansen
    0

    Add querystring to url razor

    Hi,

    I'm struggeling to insert value to a querystring in razor: Here's what I've got:

    rowTemplate = rowTemplate.Replace(string.Concat("{{url}}"), Umbraco.Content(Convert.ToInt32(annonce.Id)).NiceUrl());

    What I want to do is to insert this after .NiceUrl()?date=DateTime.Now.ToString("dd-MM-yyyy"));

    But that doesn't work.

    I get this error: Compiler Error Message: CS1003: Syntax error, ':' expected

    Can anybody help me out here?

    Regards Palle

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 26, 2017 @ 10:12
    Dennis Aaen
    0

    Hi Palle,

    I can see that you have 2 closing brackets for the DateTime.Now.ToString("dd-MM-yyyy")) but only one open bracket

    Try to use this code snippet below.

    @{
       var currentDate = DateTime.Now.ToString("dd-MM-yyyy"); 
       <a href="@Umbraco.NiceUrl(CurrentPage.Id)?date=@currentDate">@CurrentPage.Name</a>
    }
    

    Hope this helps, or can help you a step further.

    /Dennis

  • Palle Hansen 143 posts 396 karma points
    Feb 26, 2017 @ 10:34
    Palle Hansen
    0

    Hi Dennis.

    Thanks for your reply.

    No luck I'm afraid. Get the same error.

    The code is in a cs. file in the App_Code folder if that should do any difference.

    /Palle

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 26, 2017 @ 10:44
    Dennis Aaen
    0

    Hi Palle,

    Okay try to see to see Kevin JumpĀ“s comment in this thread.

    https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/68294-add-current-query-string-to-niceurl-and-niceurlwithdomain-methods

    Hope this helps,

    /Dennis

  • Palle Hansen 143 posts 396 karma points
    Feb 27, 2017 @ 18:50
    Palle Hansen
    101

    Hi Dennis.

    I got it working with this: rowTemplate = rowTemplate.Replace(string.Concat("{{url}}"), string.Concat(Umbraco.Content(Convert.ToInt32(annonce.Id)).Url(), "?date=", DateTime.Now.ToString("yyyy-MM-dd")));

    Just if anyone else could use it.

    /Palle

Please Sign in or register to post replies

Write your reply to:

Draft