Form-Label always property name instead display name

1 Answer 730 Views
Form
Daniel
Top achievements
Rank 3
Iron
Iron
Iron
Daniel asked on 30 Aug 2021, 01:41 PM | edited on 30 Aug 2021, 01:44 PM

Hey everybody,

I'm experimenting with the Kendo Forms and I recognized that building/rendering the form with razor all labels showing the property name itself instead the display name I set in the model.

@(Html.Kendo().Form<Provider>()
            .Name("form")
            .Validatable(v =>
            {
                v.ValidateOnBlur(true);
                v.ValidationSummary(vs => vs.Enable(false));
            })
            .Items(items =>
            {
                items.Add().Field(x => x.Description).Editor(x => x.Editor());
                items.Add().Field(x => x.Url);
            })
        )

My model has set a display name for the properties.

    public class Provider
    {
        [Display(Name = "Kurzbeschreibung")]
        public string Description { get; set; }

        [Display(Name = "Link zur Website")]
        public string Url { get; set; }
    }
The view is showing the property name "Description" als label text instead the display name "Kurzbeschreibung". Is this behavior expected? If not I have to set for all fields I'm gonna use a title text for the frondend. It would be easier und beautiful when the form could automatically use the display name.

1 Answer, 1 is accepted

Sort by
1
Accepted
Aleksandar
Telerik team
answered on 02 Sep 2021, 07:09 AM

Hi Daniel,

I agree with you it would be easier and more elegant to just use the DisplayName for the Label. This is however not yet supported, but we have a Feature Request on this functionality available here:

Enable DataAnnotation "DisplayAttribute.Name" property in the Form

I have cast a vote on it on your behalf, to increase it's priority. Unfortunately, until this is implemented in order to customize the Label you will have to use the .Label() configuration option:

.Items(i =>
                {
                    i.Add()
                         .Field(f => f.MyProperty)
                         .Label(l => l.Text("MyPropertyLabel:"));
                })

Let me know if I can help any further.

Regards,
Aleksandar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Form
Asked by
Daniel
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
Aleksandar
Telerik team
Share this question
or