Copied to clipboard

Flag this post as spam?

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


  • Seweb_Francesca 16 posts 86 karma points
    Oct 10, 2016 @ 13:27
    Seweb_Francesca
    0

    if statemente in partial view

    hallo i wrote this partial view to test remote address:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ string currentURL = ""; var ParzialUrl="";

    currentURL = Request.ServerVariables["REMOTE_ADDR"];

    ParzialUrl=currentURL.Substring(0,7);

    @if(ParzialUrl=="100.00.") {

    TEST

    } }

    ===> the statement IF does't work, How i can do it???

  • Steve Morgan 1350 posts 4460 karma points c-trib
    Oct 10, 2016 @ 13:53
    Steve Morgan
    0

    Hi,

    It's hard to tell from your post - suspect the forum has messed up your code but I don't think you need the @ before the if statement.

    You only need this when you're mixing razor with HTML - I like to think of it as putting the view into "code mode". If you're already in a code block like:

    @{
    
    // this is a code block 
    
    }
    

    Then don't prefix code with @ - it's for mixing in with Html like:

        <div>
    <a href="@(Model.Content.Url)">My Link</a>
    </div>
    
  • Seweb_Francesca 16 posts 86 karma points
    Oct 10, 2016 @ 13:59
    Seweb_Francesca
    0

    thanks, this is my whole code:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{

    string currentURL = "";
     var ParzialUrl="";
    
    currentURL = Request.ServerVariables["REMOTE_ADDR"];
    
    ParzialUrl=currentURL.Substring(0,7);
    

    @if(ParzialUrl=="172.20.") {

    TEST URL

    }

    }

    What is wrong???

  • Steve Morgan 1350 posts 4460 karma points c-trib
    Oct 10, 2016 @ 14:03
    Steve Morgan
    0

    Remove the '@' from the if.

  • Seweb_Francesca 16 posts 86 karma points
    Oct 10, 2016 @ 14:09
    Seweb_Francesca
    0

    It Works! Thanks!!!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies