Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Help with c# and bool on asp.net mvc

Whats the best way to print out "Yes" or "No" depending on a value

In my view I want to print out

Model.isStudent

and I dont want True or False, I want Yes or No.... do I Have to write if else statement?

like image 469
nacho10f Avatar asked Feb 03 '10 14:02

nacho10f


People also ask

Is C easy for beginners?

C is not just what students use to learn programming. It's not an academic language. And I would say it's not the easiest language, because C is a rather low level programming language. Today, C is widely used in embedded devices, and it powers most of the Internet servers, which are built using Linux.

Is C hard to learn?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.


1 Answers

Write a helper method:

public static class MyExtensions
{
    public static string FormatBool(this HtmlHelper html, bool value)
    {
        return html.Encode(value ? "Yes" : "No");
    }
}

And use it like this:

<%= Html.FormatBool(Model.IsStudent) %>
like image 86
Darin Dimitrov Avatar answered Nov 07 '22 15:11

Darin Dimitrov