Copied to clipboard

Flag this post as spam?

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


  • Kate 267 posts 610 karma points
    Oct 03, 2013 @ 12:42
    Kate
    0

    error in my if-statement

    What is wrong with this piece of code? I get this error:
    d:\web\localuser\zicon.dk\contour\macroScripts\635164008321083221_loop.cshtml(27): error CS1026: ) expected

    @for(var i =1; i < 5; i++)
    {
    if(Model.HasValue("item" + i)){

    var dateItem = @Model.GetPropertyValue("date" + i);
    var postDate = umbraco.library.FormatDateTime(dateItem.ToString(), "dd/MM/yyyy");
    var tester = umbraco.library.DateGreaterThanOrEqualToday(@dateItem);

    if (1 < 2){
    <p>jjj</p>
    }
    <p>I am @tester </p>
    <p>@Model.GetPropertyValue("item" + i) og @postDate</p>

    }

    }

    it works fine if I dont have the if(1<2){}

    What I want to do is to say if(@tester == true){
         "Do this"
    }

    Maybe it's my variables is wrong with. Because if I move the variables outside of the first if-statement i also get an error:
    c:\aspnettemp\v4.0.30319\x86\root\c379af71\9e87e254\App_Web_635164006886192701_loop.cshtml.70df5e80.emdpysem.0.cs(111): error CS1513: } expected

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Oct 03, 2013 @ 12:47
    Dennis Aaen
    0

    Hi Kate,

    Try to write the tester variable like this and see if it´s solve your problem:

    var tester = umbraco.library.DateGreaterThanOrEqualToday(dateItem);

    /Dennis

  • Kate 267 posts 610 karma points
    Oct 03, 2013 @ 12:49
    Kate
    0

    Nope, sorry it did not help :-)

  • Kate 267 posts 610 karma points
    Oct 03, 2013 @ 13:22
    Kate
    1

    Hmm, now this works, but only if I have the <p> tag in line 6. Without that line it gives me an error.
    Does anyone have an explanation?

    Is there something wrong in the vay I write the variables?

    @for(var i =1; i < 5; i++)
    {
    var fff = @Model.GetPropertyValue("date" + i);
    var postDate = umbraco.library.FormatDateTime(fff.ToString(), "dd/MM/yyyy");
    var tester = umbraco.library.DateGreaterThanOrEqualToday(@fff);
    <p>vv</p>

    if(Model.HasValue("item" + i)){
    <p>I am @tester </p>
    <p>@Model.GetPropertyValue("item" + i) og @postDate</p>
    if(@tester == false){
    <p>hej</p>
    }
    }

    }
  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Oct 04, 2013 @ 12:34
    Jeavon Leopold
    0

    Hi Kate,

    I cant see a specific syntax issue but you did have a few unnecessary @ that can cause problems, give this a try

    @for(var i =1; i < 5; i++)
    {       
        var fff = Model.GetPropertyValue("date" + i);
        var postDate = umbraco.library.FormatDateTime(fff.ToString(), "dd/MM/yyyy"); 
        var tester = umbraco.library.DateGreaterThanOrEqualToday(fff);
    
        if(Model.HasValue("item" + i)){     
            <p>I am @tester </p>
            <p>@Model.GetPropertyValue("item" + i) og @postDate</p> 
                if(tester == false){
                    <p>hej</p>
                }
        }
    
    } 
    

    Jeavon

  • Kate 267 posts 610 karma points
    Oct 04, 2013 @ 15:06
    Kate
    0

    It works perfectly :-)
    I have not quite figured out what the rule is for when to use @ or leave it out :-)

    Thanks for your help

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Oct 04, 2013 @ 15:13
    Dennis Aaen
    0

    Hi Kate,

    Try to see if you could use my first and last post in this topic.

    http://our.umbraco.org/forum/developers/razor/45137-What-is-@Model

    /Dennis

  • 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