开发者

ASP.NET MVC 2 Calling html helper inside if conditional statement

I'm having a problem getting the syntax correct. The html helper returns true or false.

<开发者_开发百科;% if (<%= Html.SecurityTrim("Admin")%>) { %>  
            <span>Only for accounting</span> 
    <% } %>

What do I need to change to get this to compile correctly?


Supposing that Html.SecurityTrim() returns bool,

<% if ( Html.SecurityTrim("Admin") ) { %>  
    <span>Only for accounting</span> 
<% } %>


Sounds like your Html.SecurityTrim() returns a bool.

In this case, then no need to escape out of code, just use it as your condition to test.

<% if (Html.SecurityTrim("Admin")) { %>  
            <span>Only for accounting</span>   
  <% } %>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜