Настройка текста, отображаемого с помощью вспомогательного метода LabelFor ()

Как я могу настроить текст, который отображается с помощью метода LabelFor ()?

У меня есть bool-поле с именем IsMarried в моей модели, Как я могу сказать что-то вроде: «Женат».

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<TeacherEvaluation.Models.GuestBookEntry>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
 GuestBook Index
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Guest Book</h2>

    <p>Please sign the Guest Book!</p>

    <% using (Html.BeginForm()) { %>

       <fieldset>
            <legend>Guest Book</legend>

            <%: Html.LabelFor(model => model.Name) %>
            <%: Html.TextBoxFor(model => model.Name) %>

            <%: Html.LabelFor(model => model.Email) %>
            <%: Html.TextBoxFor(model => model.Email) %>

            <%: Html.LabelFor(model => model.Comment) %>
            <%: Html.TextAreaFor(model => model.Comment, new { rows = 6, cols = 30 })%>       

            <%: Html.LabelFor(model => model.IsMale) %>
            <%: Html.CheckBoxFor(model => model.IsMale) %>     

            <div>
                <input type="submit" value="Sign" />
            </div>
        </fieldset>

    <% } %>

</asp:Content>

Спасибо!

1
задан 25 August 2010 в 12:46
поделиться

2 ответа

Используйте DisplayNameAttribute вместо свойства вашего класса. Например:

class GuestBookEntry
{
      //...

      [DisplayName("Married")]
      public bool IsMarried { get; set; }

      //...
}
0
ответ дан 2 September 2019 в 21:51
поделиться

Добавьте атрибут DisplayNameAttribute к свойству модели IsMarried:

[DisplayName("Married")]
public virtual bool IsMarried {get;set;}
2
ответ дан 2 September 2019 в 21:51
поделиться
Другие вопросы по тегам:

Похожие вопросы: