Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ASP.NET Change text based on incoming value

I have a page like this:

enter image description here

As you can see, there are True and False values ​​in the Urgent and Done sections. I want to change these posts.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I want it to write "Yes" if True and "No" if False. How I can do that?

My codes:

@using ToDoListApp.Models
@model List<TodoTable>

<table class="table table-hover">
    <thead>
        <tr>
            <th scope="col">ID</th>
            <th scope="col">Task</th>
            <th scope="col">Urgent</th>
            <th scope="col">Done</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model) {
            <tr>
                <th scope="row">@item.Id</th>
                <td>@item.Name</td>
                <td>@item.Urgent</td>
                <td>@item.Done</td>
            </tr>
        }
    </tbody>
</table>

Thanks for help.

>Solution :

You can use an @if or for cleaner code you can use the ternary operator : ?.

<td>@(item.Urgent ? "Yes" : "No")</td>
<td>@(item.Done ? "Yes" : "No")</td>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading