Copied to clipboard

Flag this post as spam?

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


  • Simeon Ostberg 123 posts 389 karma points
    Aug 27, 2020 @ 13:01
    Simeon Ostberg
    0

    Hide partials by URL part?

    Hi everyone,

    I was wondering, if it is possible to hide partial views by URL part? For example:

    www.example.com/example
    

    for the full page, and:

    www.example.com/example?hidefooter=1
    

    to show the same page, but without the footer? And that I could use this URL in an IF-THEN-ELSE clause to hide the partial view?

    Thanks everyone! Simeon

  • Steve Morgan 1349 posts 4458 karma points c-trib
    Aug 27, 2020 @ 17:24
    Steve Morgan
    0

    In your partial you could just write something like:

    @if (Request.QueryString["hidefooter"] != null && int.Parse(Request.QueryString["hidefooter"]) == 1)
            {
                <footer></footer>
            }
    
  • Simeon Ostberg 123 posts 389 karma points
    Aug 28, 2020 @ 07:06
    Simeon Ostberg
    0

    Hi Steve,

    Thanks a lot for your reply!

    I just tried that, but unfortunately it doesn't work. There is no difference, if I try with or without ?hidefooter=1.

    This is my code:

    @if (Request.Params["hidefooter"] != null && int.Parse(Request.Params["hidefooter"]) != 1)
        {
            <footer></footer>
        }
        else
        {
            (my footer code)
        }
    

    Is this correct?

    Thanks!

  • Steve Morgan 1349 posts 4458 karma points c-trib
    Aug 28, 2020 @ 08:31
    Steve Morgan
    100

    Sorry - didn't engage the brain before posting. I've updated the code snippet - there were two errors there :)

  • Simeon Ostberg 123 posts 389 karma points
    Aug 28, 2020 @ 08:48
    Simeon Ostberg
    1

    That worked, thanks! :)

Please Sign in or register to post replies

Write your reply to:

Draft