set attribute regarding to condition ASP.net MVC - asp.net-mvc

Is there anyway to do this?
<tr #if (i % 2 == 0) { class="odd" }>

Try it like this
<tr class=#(i % 2 == 1 ? "odd" : "even")>...</tr>

Related

I try to write a condition in thymeleaf with OR

I need to have a condition with logical operator OR. I try to do in this way but it seem doesn't work :
<div th:if="${(fingerprints.totalPages != 0) or (fingerprints.totalPages != 1)}"
How I suppose to do ? :)
Both or and || work. In this case, your logic is wrong. I think your expression should be:
th:if="${(fingerprints.totalPages != 0) and (fingerprints.totalPages != 1)}"
Your original expression is always true. (Since fingerprints.totalPages is always going to be either != 1 or != 0.

Struts 2 s:if Vs struts 1 logic:notEqual - null handling

The following struts 1 code evaluates to true when row.type is null.
<logic:notEqual property="type" name="row" value="head">
The same I converted into struts2 as below but it evaluates to false when row.type is null.
<s:if test='%{! #row.type.equals("head")}'>
How to make this true when #row.type is null.
Tried as below still not working.
<s:if test="%{#row.type != null}">
// Control Not going inside
</s:if>
<s:if test='%{(! #row.type.equals("head") ) || #row.type == null}'>
// here also not going inside
</s:if>
Try
<s:if test='%{! "head".equals(#row.type)}'>
Using parentheses helped.
<s:if test='%{ ! ("head".equals(#row.type)) }'>

Using Ternary operation in the if condition - Objective C

I am trying to check to find out whether or not numberOfItemsPerSection is bigger than 3 in the if condition. It always returns true. Then I decided to debug.
How is it possible that indexPath.row equals to 1 and numberOfItemsPerSection = 20 and it goes into to the if condition.
What am I doing wrong by using the following ternary operator?
if(indexPath.row == (numberOfItemsPerSection > 3) ? (numberOfItemsPerSection-4) : numberOfItemsPerSection)
{
}
Use parenthesises to resolve priority. Change the condition by below way. Just cover your turnery condition with parenthesis. It will resolve the turnery operator first and then it will compare it to indexPath.row.
if(indexPath.row == ((numberOfItemsPerSection > 3) ? (numberOfItemsPerSection-4) : numberOfItemsPerSection))
NSInteger desiredRow = numberOfItemsPerSection > 3 ? (numberOfItemsPerSection-4) : numberOfItemsPerSection;
if(indexPath.row == desiredRow) { ... // do your coding }
You can write:
if (indexPath.row == (numberOfItemsPerSection > 3 ? numberOfItemsPerSection - 4 : numberOfItemsPerSection)) { ... }
Or if you don't want to hurt your eyes:
BOOL desiredRow = numberOfItemsPerSection > 3 ? numberOfItemsPerSection - 4 : numberOfItemsPerSection;
if (indexPath.row == desiredRow) { ... }

DTM: How to add multiple class or multiple id in a selector?

I need to create a single event rule for the below anchor tags. I have 2 classes to add or i can use id.
<a id="Message1" class="read">test1</a>
<a id="Message2" class="unread">test2</a>
In my event rule i have added a as selector and then used custom code like below to capture id or class. Both dint work. What is the issue here?
if ( $(this).attr('id').indexof("Message") > 0 ) {return true;} else {return false;}
if ( $(this).attr('class') == "read" || $(this).attr('class') == "unread" ) {return true;} else {return false;}

Expressionengine concat inside if

What is the proper way to cocatenate strings inside if statement?
For ex.:
{if {site_url}{segment_1} == page_url} class="selected" {/if }
I need to concatenate *site_url* and *segment_1* then compare it to *page_url*.
On Expressionegine conditionals you can use
{if {var} == ''} or {if "{var}" == ''}
Maybe it work
{if "{site_url}{segment_1}" == "page_url"} class="selected" {/if }

Resources