I am using asp.net mvc and I have a table with value.
When the customer paid value = 0. I want it to display No payment in the cell.
When it Customer paid = 1. I want it to display.
Pending.
When it = 2 i want it to display Paid.
I am attempting to write an inline code block to display payment status based on the value of the Paid
property on my Customer
class. If the value is "0", I need to display an empty cell. If the value is "1" I need to print "Pending" into the cell, and if the value is "2" I need to print "Paid".
I have the following already, but I am not sure how to get the value into the cell.
<%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>
<%}%>
They're called code delimiters.
<%=Customer.FirstName%>
outputs a value
<%= if(Customer.Paid==0)
{
Customer.Paid== "No Payment";
};%>
Above, you aren't outputting a value, so no =
sign is required.
I'm no ASPX expert, but wouldn't this work?
<td>
<% if(Customer.Paid==0) { %>No payment<% } %>
<% else if(Customer.Paid==1) { %>Pending<% } %>
<% else { %>Paid<% } %>
</td>
or, if you want it in one line
<td>
<%= Customer.Paid == 0 ? "No payment" : (Customer.Paid == 1 ? "Pending" : "Payed") %>
</td>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.