2010-07-01 76 views
0

我在conrtoller中有一个操作结果方法,它将IList返回给我的视图。现在,Ilist从数据库中返回一组行。其中的一些列是位值。现在 当我显示这些行时,位值显示为true和false。如果值为真,则需要检查IF条件,然后显示“是”,否则显示“否”。我收到一个错误说编译器错误信息: CS0103:“真”的名字没有出现在目前情况下存在查看中的ASP.NET MVC IF条件

<% if(Model.Count < 1) 
      {%> 
        No User's Add Under You! 
     <% } else { 
      foreach (var item in Model) { %> 
      <tr> 
      <td class="usertd"><%= Html.Encode(item.UserName) %> </td> 
      <td class="usertd"><%= Html.Encode(item.Role) %></td> 
      <td class="usertd"><%= Html.Encode(item.Email)%> </td> 
      <td><% if (item.EmailDoc.Equals(True)) { %> 
       Yes <% } else { %> 
       No <% } %> 
      </td> 
      <td class="usertd"><%= Html.Encode(item.EmailDoc)%></td> 
      <td class="usertd"><%= Html.Encode(item.PrintDoc)%></td> 
      <td class="usertd"><%= Html.Encode(item.DownloadDoc)%></td> 
      <td class="usertd"><input type="button" value="Edit User"/></td> 
      </tr> 
      <% } 
     } %> 

回答

2

C#是case sensitive实际上:

<% if (item.EmailDoc.Equals(true)) { %> 

这当然可能是简化为:

<% if (item.EmailDoc) { %> 

但是如果你的item.EmailDoc属性是string你需要做的字符串比较(在这种情况下,它并不是真正意义上的字符串,但无论如何):

<% if (item.EmailDoc == "True")) { %> 
+0

谢谢,这对我很有用 – Pinu 2010-07-01 19:12:41