This is a migrated thread and some comments may be shown as answers.

How to set label for foreign key fields in popup editor

2 Answers 274 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Edward
Top achievements
Rank 1
Edward asked on 04 Jan 2019, 06:23 AM

Have a field in ViewModel:

[Required]
[UIHint("ValueViewTemplate")]
[Display(Name = "Approval Type")]
public int ApprovalTypeId { get; set; }

||||||||||||||||||||||||||||||||||||||||||||||||||||

Using GridEditMode.PopUp:

||||||||||||||||||||||||||||||||||||||||||||||||||||

ValueViewTemplate is:

@model object

@(Html.Kendo().DropDownListFor(m => m)
                        .DataValueField("Id")
                        .DataTextField("Value")
                        .OptionLabel("- Select -")
                        .BindTo((System.Collections.IEnumerable)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty)])
                        .Template("<span class=\"drop-down-list-item\" title=\"#=Value#\">#=Value#</span>")
)

||||||||||||||||||||||||||||||||||||||||||||||||||||

Works, but only problem is the label is not showing "Approval Type" from [Display(Name = "Approval Type")] of the viewmodel, but the actual field name of ApprovalTypeId.

 

What should one do..?  First time using Grid control... thnks.

 

2 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 07 Jan 2019, 12:30 PM
Hi Edward,

Since I have already answered the same question in your support ticket, I will paste the answer here as well in case someone else has the same query.

=====================================

I have tested the described behavior on my end using the same Asp.Net Core and Kendo UI versions. However, the value from the Display attribute is set as a value of the label.

For your convenience I am attaching the sample I used for testing. Could you please examine it and let me know if I am missing something?

=====================================


Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Edward
Top achievements
Rank 1
answered on 07 Jan 2019, 09:40 PM

Emailing perhaps should have also included my grid column definition for the foreign key field in the problem definition...

It was:
columns.ForeignKey(o => o.ApprovalTypeId, (System.Collections.IEnumerable)ViewData["ApprovalTypeId"], "Id", "Value").EditorTemplateName("ValueView");

 

Apparently using "ApprovalTypeId" (same as the foreign key field name) for the ViewData key was somehow causing the Display attribute not be picked up.

Not sure, but simply changing the ViewData key to be different from the foreign key field name, such as "ApprovalTypeId-Data" seems to fix the issue...


Tags
Grid
Asked by
Edward
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Edward
Top achievements
Rank 1
Share this question
or