Show fixed text based on dropdown value
It is possible to show a fixed text based on the value of the dropdown field.
For example:
-
if the Type of organism is Yeast, then show the contact details of person A.
-
if the Type of organism is Bacteria, then show the contact details of person B.
-
etc.
<tr>
<td>@Model.T288.Label</td>
<td>
@{if(@Model.T288.ToString() == "Yeast")
<span>this is a yeast, contact person A</span>
else if(@Model.T288.ToString() == "Bacteria")
<span>this is a bacteria, contact person B</span>
}
</td>
</tr>
Extra explanation on the code:
-
== "Yeast" if the value of the field is Yeast, then show this text.
-
else if ... == "Bacteria" if the value is not Yeast, but it is Bacteria, then show that text.
The result looks like:
-
BIO 1355 is a Yeast.
-
BIO 1356 is a Bacteria.
The code placed in a table:
<table class="table">
<thead>
</thead>
<tbody>
<tr>
<td>@Model.T288.Label</td>
<td>
@{if(@Model.T288.ToString() == "Yeast")
<span>this is a yeast, contact person A</span>
else if(@Model.T288.ToString() == "Bacteria")
<span>this is a bacteria, contact person B</span>
}
</td>
</tr>
</tbody>
</table>
When the unknown/default value should not be shown then use the following code:
@if (@Model.V811.ToString() != "Unknown") {
@Model.V811
}