Can someone quickly tell me if my syntax is correct for these conditions in my If statement in Razor?
var item = (an incremental number); var rows = (an incremental number); var numInRow = (guess what, an incremental number!);
if (item % numInRow == 0 && rows == 1) {
}
I've checked it with just rows == 1 and that works. So its really the item % numInRow == 0 part thats causing the error. (Checking to see if item is a multiple of numInRow).
Sorry for delayed reply. I discovered another way of acheiving what I needed. However, I think it's now irrelevent to this issue! But thank you for your help. I now make sure I'm declaring the type instead of just using var.
Razor If conditional super quick syntax check
Can someone quickly tell me if my syntax is correct for these conditions in my If statement in Razor?
I've checked it with just rows == 1 and that works.
So its really the item % numInRow == 0 part thats causing the error. (Checking to see if item is a multiple of numInRow).
Thanks!
Assuming item, numInRow and rows are all integers then your syntax is fine. What error are you getting?
I am sure that % is something diffrent. What does int test = item % numInRow; give you?
You do not need to use var i dont think you the type you know will be returned.
Sorry for delayed reply. I discovered another way of acheiving what I needed. However, I think it's now irrelevent to this issue! But thank you for your help. I now make sure I'm declaring the type instead of just using var.
A fun, but apparently well-hidden and non-documented alternative, is to use the
InGroupsOf
method which can make your code a little easier to read and write. Helpful-looking blog post here in lieu of any official documentation : http://www.simonantony.net/knowledge-base/articles/grouping-nodes-in-umbraco-razor/Good luck!
is working on a reply...