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

ForeignKey and UIHint

2 Answers 819 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Louis
Top achievements
Rank 1
Iron
Iron
Iron
Louis asked on 25 Oct 2019, 12:40 AM

Hello,

 

It's seem that ForeighKey always use GridForeignKey.cshtml…

I try to decorate the attribute UIHint with another cshtml (Shared/EditorTemplates) and it's not working.  My dropdown list in the grid always use GridForeignKey.cshtml.

 

Any idea?

2 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 25 Oct 2019, 07:21 AM

Hi Louis,

 

This requirement is actually possible. You can follow the implementation demonstrated in this live sample to achieve this:
https://demos.telerik.com/aspnet-core/grid/editing-custom

I hope this will prove helpful.

 

Regards,
Eyup
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.
-1
Louis
Top achievements
Rank 1
Iron
Iron
Iron
answered on 26 Oct 2019, 01:45 AM

Hello Eyup,

Hummm not really but I found the solution elsewhere.

Have great week-end.

Trent
Top achievements
Rank 1
commented on 04 Mar 2023, 11:00 PM

If you are still on the forums, can you please post the solution.

 

Alexander
Telerik team
commented on 08 Mar 2023, 04:44 PM

Hi Trent,

Thank you for reaching out.

Indeed, internally, the Grid ForeignKey column will use a default DropDown editor, and thus the observed behavior will occur. Having this in mind, the ForeignKey() method has an overload, where you can specify that the column should use a server editor ("useServerEditor" boolean parameter):

https://docs.telerik.com/aspnet-core/api/kendo.mvc.ui.fluent/gridcolumnfactory#foreignkeysystemlinqexpressionsexpressionsystemactionsystemstringsystemstringsystemboolean

To enable the custom editor template, please update the column configuration as per the example below:

.Columns(columns =>
{
    columns.ForeignKey(p => p.FirmID,ds=>ds.Read(r=>r.Action("GetFirms","Home")), "FirmID", "FirmName",true)
      .Title("Firm").EditorTemplateName("FirmGridForeignKey").Width(250);
})

For your convenience, I am also attaching a runnable sample that showcases the mentioned above. Please give the suggestion a try and let me know how it works out for you.

I hope this helps.

Tags
Grid
Asked by
Louis
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Eyup
Telerik team
Louis
Top achievements
Rank 1
Iron
Iron
Iron
Share this question
or