Answer the question
In order to leave comments, you need to log in
C# how to use an attribute to change the output of a property of type bool?
Good evening.
Can you tell me how to change the bool type output in html markup using an attribute in C#?
Class code:
public class Student
{
[DisplayName("Пол")]
public bool? Gender { get; set; }
[DataType(DataType.Date)]
[DisplayName("Дата рождения")]
public DateTime? Birthday { get; set; }
}
@model NameSpace.Models.DataModel.Student
@Html.EditorForModel(new { htmlAttributes = new { @class = "form-control" } })
Answer the question
In order to leave comments, you need to log in
Found the following solution:
Add the following attribute to the class [UIHint("Gender")]
public class Student
{
[DisplayName("Пол")]
[UIHint("Gender")]
public bool? Gender { get; set; }
[DataType(DataType.Date)]
[DisplayName("Дата рождения")]
public DateTime? Birthday { get; set; }
}
@model bool?
<select class="list-box tri-state" id="Gender" name="Gender"><option value="">Не задано</option>
<option selected="selected" value="true">Мужской</option>
<option value="false">Женский</option>
</select>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question