Neb Neb - 8 months ago 45 Question

Razor if statement inside HTML

Why I can do that:

Dim styleVisible As String = if(Model.IndicateurAchatPeriodique,"block","none")
End Code
<div id="@sectionDCAId" style="display:@styleVisible">...

but not that:

<div id="@sectionDCAId" style="display:@If(Model.IndicateurAchatPeriodique,"block","none")">

I just moved the if instruction inside the HTML but it throw an error. Why the compiler can't understand it?
I don't need solutions, just an explanation. Thanks


The compiler seems to have problems with inline VB.NET Ifs. Not sure if it is a bug or it just isn't quite that clever. I know you haven't asked for a solution, but if you put an extra set of brackets in to help it then it will probably work - as in @(If(Model.IndicateurAchatPeriodique,"block","none"))