2011-10-22 149 views
0


在@if語法中不允許...如何在razor @if中添加間距邊距?

問:如何在剃鬚刀@if {}塊中添加間距/邊距?

@if (User.IsInRole("Admin")) 
{  
    @* I need to add certain bottom margin here *@ 
} 
else 
{ 
    @* I need to add certain bottom margin here *@  
} 

@* More stuff down here ... *@ 

回答

1
@{ 
    var margin = string.Empty; 
    if (condition1) 
    { 
     margin = "10px";; 
    } 
    else if (condition2) 
    { 
     margin = "20px"; 
    } 
} 

<div style="margin-bottom: @margin"> 
my stuff 
</div> 

這是很多方法可以做到這一點

+0

巨星之一!謝謝! – Mariah