I have a JSON file where I am using a foreach loop to loop through that file. Everything is working just fine. At the moment everything is printed in the below code.
@{ bool anyRoomsForChildrenUnder4 = false; foreach (var room in Model.Order.OrderLines) { anyRoomsForChildrenUnder4 = room.NumberChildren0to3 > 0; if (anyRoomsForChildrenUnder4) { break; } } } <html xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body> @{bool prcb = !string.IsNullOrWhiteSpace((string)Model.Order.Store.JsonDynamic.Da.HotelData.PaymentRequiredForChildrenBreakfast); } <tr> <th class="small-12 large-6 columns first"> <table> <tr> <th width="300"> <p class="text-left small-text-left"> @if (prcb) { <strong>Lunch for children under 3</strong> } </p> </th> </tr> </table> </th> <th class="small-12 large-6 columns last"> <table> <tr> <th width="300"> <p class="text-left small-text-left"> @if (prcb) { <span>@Model.Order.Store.JsonDynamic.Da.HotelData.PaymentRequiredForChildrenBreakfast</span> } </p> </th> <th class="expander"></th> </tr> </table> </th> </tr> <!-- Price for children breakfast--> @{bool pfcf = !string.IsNullOrWhiteSpace((string)Model.Order.Store.JsonDynamic.Da.HotelData.PriceForChildrenBreakfast); } <tr> <th class="small-12 large-6 columns first"> <table> <tr> <th width="300"> <p class="text-left small-text-left"> @if (pfcf) { <strong>OA dummy text for now</strong> } </p> </th> </tr> </table> </th> <th class="small-12 large-6 columns last"> <table> <tr> <th width="300"> <p class="text-left small-text-left"> @if (pfcf) { <span>@Model.Order.Store.JsonDynamic.Da.HotelData.PriceForChildrenBreakfast</span> } </p> </th> <th class="expander"></th> </tr> </table> </th> </tr> </body> </html> But The below code only needs to get printed if the (anyRoomsForChildrenUnder4) is true. If it is not true, the below code should not execute.
(anyRoomsForChildrenUnder4) > 0 : true -> Print
(anyRoomsForChildrenUnder4) = 0 : false -> Do not print
Does anybody knows how I can do that?
ifstatement would do exactly what you want.