簡體   English   中英

<%%> <-這叫什么? 如何在其中編寫C#代碼

[英]<% %> <--What is this called? How do I write C# code in it

我正在使用asp.net mvc,並且具有帶值的表。 當客戶支付的值= 0時,我希望它在單元格中顯示“無付款”。 當它客戶支付=1。我希望它顯示。 待定。 當它= 2時,我希望它顯示“已付費”。

我試圖編寫一個內聯代碼塊,以基於我的Customer類上Paid屬性的值來顯示付款狀態。 如果值為“ 0”,則需要顯示一個空單元格。 如果值為“ 1”,則需要在單元格中打印“待處理”,如果值為“ 2”,則需要打印“已付費”。

我已經有以下內容,但是我不確定如何將值獲取到單元格中。

<%foreach (var Customer in CustomerList)  {%>
  <tr>
    <td><input type="radio" value="<%= Customer.ThirdPartyCustomerId %>" /></td>
    <td><%=Customer.FirstName%></td>
    <td><%= if(Customer.Paid==0)
            {
                Customer.Paid== "No Payment";
            };%>
    </td>        
 </tr>
<%}%>

它們被稱為代碼定界符。

<%=Customer.FirstName%>輸出一個值

<%= if(Customer.Paid==0)
            {
                Customer.Paid== "No Payment";
};%>

在上面,您沒有輸出值,因此不需要=符號。

我不是ASPX專家,但是這行不通嗎?

<td>
    <% if(Customer.Paid==0) { %>No payment<% } %>
    <% else if(Customer.Paid==1) { %>Pending<% } %>
    <% else { %>Paid<% } %>
</td>

或者,如果您想要一行

<td>
    <%= Customer.Paid == 0 ? "No payment" : (Customer.Paid == 1 ? "Pending" : "Payed") %>
</td>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM