This question already has an answer here:
- Help with c# and bool on asp.net mvc 3 answers
Here's my page code so far:
@model TennisClub.Models.ClubMember
@{
ViewBag.Title = "Details";
}
<h2>
Details
</h2>
<fieldset>
<legend>ClubMember</legend>
@Html.DisplayForModel()
</fieldset>
<p>
@Html.ActionLink("Edit", "Edit", new { id = Model.Id }) |
@Html.ActionLink("Back to List", "Index")
</p>
For all the nullable bools (bool?
) in my model, this displays a dimmed select list with either Not Set, True, or False. I'd like it to be just plain text: either Not Set, Yes, or No.
How can I achieve this most easily? I'd like this style to be global throughout my site.
Edit
Just took a stab at making a template per Mark's answer, but the details page looks exactly the same.
I created a bool.cshtml file and placed it in the following folder:
[ProjectFolder]/Views/Shared/DisplayTemplates
Here's what I have for my bool.cshtml template at the moment:
@model bool?
@if (Model == null)
{
<text>Not Set</text>
}
else
{
if (Model.Value)
{
<text>Yes</text>
}
else
{
<text>No</text>
}
}
This doesn't seem to have any affect on my details pages at all.
Any idea what I'm doing wrong?
Edit 2
Here's my model class:
public class ClubMember
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
public string PhoneNumber { get; set; }
public string PhoneType { get; set; }
public bool? CanPlayDays { get; set; }
public bool? CanPlayEvenings { get; set; }
public bool? CanPlayWeekends { get; set; }
public string Role { get; set; }
}