The first three are the same (?) how come you get different output?
The fourth, with double quotes, won't work that way and you would need to escape the inner double quotes with backslashes (as per Bo's suggestion).
The fifth one *should* be correct, but it seems to me the output is being ran through an encoder to encode HTML entities before being sent to the browser - is this the case?
My gripe with the double quotes isn't that there is anything intrinsically wrong with them - they're just as valuable as most other characters, it's just that in cases like this it's a really easy way to get your code looking more messay than it needs to be, and really quickly. If you can get away from the drastics of having to escape stuff due to a 'safer' or other option, then do so. This stands in most situations, but is particularly pertinent when we're coding among HTML, where we could end up having to escape this kind of stuff on every line, twice or thrice. Nasty.
To check if the node has any sub-nodes to conditionally add the script - in fact, did I get that right? You might need to alter it for something like `node.Children.Any()` instead.
xsl:attribute done Razor?
I'm (still) new in the Razor world. I'm trying to do a multi level menu with jQuery.
My goal:
Notice...
But how do I solve it with Razor? My primary issue is to add a class to an element depending...
I have got this far in Razor:
You can use a ternary operation to get some inline output, something like the following:
I'm wondering if there should be some curly braces in there - give it a go.
Hi Grant
Your first suggestion works just fine (though I had to remove the ' in class='navCurrent' - any tips for actually getting the qoutes (")?)
Any suggestions for getting the javascript on the li-element when the node has children?
Hi Kasper,
You should be able to get the quotationmarks by good ol' escaping ;-)
Example:
All the best,
Bo
Whoa! No need to use double quotes only to escape them - just use single quotes inside the string ("class='abc'").
When I get time I can help you with the other stuff you mentioned, sure.
What's so bad about double-quotes, Grant? :-) Asking out of curiousity.
Maybe I can answer that by showing what I get...
The first three are the same (?) how come you get different output?
The fourth, with double quotes, won't work that way and you would need to escape the inner double quotes with backslashes (as per Bo's suggestion).
The fifth one *should* be correct, but it seems to me the output is being ran through an encoder to encode HTML entities before being sent to the browser - is this the case?
My gripe with the double quotes isn't that there is anything intrinsically wrong with them - they're just as valuable as most other characters, it's just that in cases like this it's a really easy way to get your code looking more messay than it needs to be, and really quickly. If you can get away from the drastics of having to escape stuff due to a 'safer' or other option, then do so. This stands in most situations, but is particularly pertinent when we're coding among HTML, where we could end up having to escape this kind of stuff on every line, twice or thrice. Nasty.
Hm.... My examples seems to bee modifired by the RTE in the forum. Let me try again.
But now back to the question :-)
I need a tip on how to add a line of javascript to a <li> that contais children.
Kasper, for the Javascript you could do much the same thing; something like this:
Preformat the script output as a string literal:
Now add it conditionally:
<a href="#" @(thingThatMightHaveChildren.Any() ? script : "")>ABC</a>
Quick question: What is the .Any() for?
To check if the node has any sub-nodes to conditionally add the script - in fact, did I get that right? You might need to alter it for something like `node.Children.Any()` instead.
Okay. Thanks for your help! I really appreciate it.
is working on a reply...