I'm developing an web app using C# and MVC. One of the page has multiple <tr>
which will contain information but this information gets updated over time (1 month to 6 month) range. So I only want to show the <tr>
which include the information. The information is stored in a database, each <tr>
has it's own column. The approach I've gone with is I read the data and apply if
conditions in the view.
So something like
@if (!string.IsNullOrEmpty(Model.SomePropertyOne))
{
<tr>
<td>@Html.DisplayNameFor(model => model.SomePropertyOne)</td>
<td>@Html.DisplayFor(model => model.SomePropertyOne)</td>
</tr>
}
@if (!string.IsNullOrEmpty(Model.SomePropertyTwo))
{
<tr>
<td>@Html.DisplayNameFor(model => model.SomePropertyTwo)</td>
<td>@Html.DisplayFor(model => model.SomePropertyTwo)</td>
</tr>
}
...
I have to this 8 times. So my question is, is there a better approach than this or am I stuck with using all these if
statements?
Please let me know if you require any further information