Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7694443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:19:21+00:00 2026-05-31T21:19:21+00:00

I have a boolean property IsActive. In the view is a list of objects

  • 0

I have a boolean property IsActive. In the view is a list of objects with their properties (including IsActive). But in the list the IsActive is a non-editable checkbox since it’s boolean. If I change DisplayFor() to DisplayTextFor() then it will just display True or false instead of checkbox. How can I change True and false to ‘Active’ and ‘Inactive’ where Active is true and Inactive is false?

      @Html.DisplayTextFor(modelItem => item.IsActive) 

And then I would style the ‘Active’ to green and ‘Inactive’ to red

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:19:22+00:00Added an answer on May 31, 2026 at 9:19 pm

    You can use a display template to format the way your property is displayed.

    Create a DisplayTemplates folder either under ~/Shared or in the View folder where the view that will be using this template exists.

    Add a new partial view to this folder. Name it anything you’d like, e.g. IsActive.cshtml

    @model bool
    @if (Model == true)
    {
        @Html.Encode("Active")
    }
    @if (Model == false)
    {
        @Html.Encode("Inactive")
    }
    

    Now add data annotation to your property to let it know to use this display template.

    [UIHint("IsActive")]
    public bool IsActive { get; set; }
    

    Use Html.DisplayFor on any bool with this annotation and it will be formatted according to the display template with the matching name. With some tweaking, you can place the color change style directly in your display template.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a nullable boolean property of an object inside a list, I want
I have a model which has a boolean property and some other properties that
I have a dataset that is essentially a list of objects with a boolean
I have a set of model objects that have a public IsVisible boolean property.
The case goes as following: You have a Boolean property called FullScreenEnabled. You enter
I have a class isSearching with a single boolean property in a 'functions' file
I have a custom object Foo with a boolean property called Flagged and when
I have an class which has a enum property and a boolean property, based
I have CustomForm inherited from Form which implements a boolean property named Prop .
I have a generic collection of type MyImageClass, and MyImageClass has an boolean property

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.