Copied to clipboard

Flag this post as spam?

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


  • Craig100 1136 posts 2523 karma points c-trib
    Mar 09, 2013 @ 15:56
    Craig100
    0

    Razor as time consuming as XSLT

    Hi,

    Having great difficulty with Razor syntax here. It's an Umb 6.0.2 site.

           var heading = sectionLeft.IsFirst("h1","h2");
            <@heading>@sectionLeft.sectionTitle</@heading>

    Puts out <h1>Some text</@(heading)> instead of <h1>Some text</h1> and I can't work out why after Googling and "ouring" for ages. I have the Razor cheat sheet but it's not helping me on syntax. Finding Razor hard going to be honest. Particularly when mixing HTML with code.

    Any pointers would be appreciated. 

    Craig

  • Craig100 1136 posts 2523 karma points c-trib
    Mar 09, 2013 @ 19:15
    Craig100
    0

    And for those, like me that were wondering, the answer is:-

    var heading = sectionLeft.IsFirst("h1","h2");
    @: <@heading>@sectionLeft.sectionTitle</@heading>

    ;)

    Craig

  • gary 385 posts 916 karma points
    Mar 10, 2013 @ 00:03
    gary
    0

    Hi Craig

    You have me intrigued 

    Given what you have above would;

    @{ var heading = sectionLeft.IsFirst("h1","h2");

    <heading>sectionLeft.sectionTitle</heading> }  be easier?

    For the var to be recognised (blue) you are in a codeblock, so do not need the @: which takes you out of codeblock, then another @heading to put you back in, kinda like a double negative?

    You can get intellisense on these in both VS and WebMatrix, so this can help sort out snippets like this.

    G

  • Craig100 1136 posts 2523 karma points c-trib
    Mar 10, 2013 @ 01:13
    Craig100
    0

    Hi Gary,

    The syntax is a nightmare. You can't tell where you are (in code or out) at any one point and it's not at all obvious.  I'm using VS2012 update 1 which has a bug to be fixed for update 2 which is no Razor intellisense, so I read yesterday.

    <heading>sectionLeft.sectionTitle</heading>  just looks so wrong and dangerous to me. <heading></heading> could be a perfectly valide html5 tag set so it should switch back to html at that point as far as I understood. Maybe I'll get used to it with experience.

    Craig

Please Sign in or register to post replies

Write your reply to:

Draft