开发者

How to format inline razor variables

Razor does a great job of knowing what you want to do when it's simple. I just want to format a variable from a query and am a bit confused. Everything works great, except the one line with the if string isnull statement in it. The compiler fails on the line with the { &nbsp } saying it expects a semicolon ;. Here's the code:

@foreach(var row in db.Query(selectQueryString)){ 
<tr> 
       <td>@row.ACCT &nbsp &nbsp</td> 
       <td>@row.QuoteStart &nbsp &nbsp</td> 
       <td>@row.VIN &nbsp &nbsp </td>
       <td>@{ if (String.IsNullOrEmpty(row.AmountFinanced) == true) 
                 { &nbsp } else 
                 {String.Format("{0:0,0.00}",row.AmountFinanced) &nbsp &nbsp }
            } </td>
       <td>@row.开发者_开发问答Step &nbsp &nbsp </td>


</tr> 
} 


You need to wrap your &nbsp;s in a <text></text> block. This forces the parser to escape back into html because when you're in a {} block the parser will assume that the &nbsp; is supposed to be code.

@foreach(var row in db.Query(selectQueryString)){ 
<tr> 
       <td>@row.ACCT &nbsp &nbsp;</td> 
       <td>@row.QuoteStart &nbsp; &nbsp;</td> 
       <td>@row.VIN &nbsp; &nbsp; </td>
       <td>@{ if (String.IsNullOrEmpty(row.AmountFinanced) == true) 
                 { <text>&nbsp;</text> } else 
                 { @String.Format("{0:0,0.00}",row.AmountFinanced) <text>&nbsp; &nbsp;</text> }
            } </td>
       <td>@row.Step &nbsp; &nbsp; </td>
</tr> 
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜