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

Inline editing nullable foreign key

2 Answers 262 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrea
Top achievements
Rank 1
Andrea asked on 15 Jul 2015, 08:55 AM

In my model I have a nullable foreign key (DocumentCausalID) and the foreign object (DocumentCausal).

I'm using the default "GridForeignKey" editor template to choose the value using the DropDownList.

I've edited the default "GridForeignKey" adding the OptionLabel so I can choose a null value.

When I select the null value it update the row correctly, but the next time if I select a not-null value on the same row it doesn't work: it doesn't enter into the Update function of my controller.

 Can you help me? (I've attached my Model, View and the Editor Template)

 

Thank you

2 Answers, 1 is accepted

Sort by
0
Andrea
Top achievements
Rank 1
answered on 15 Jul 2015, 12:50 PM

I have also tried to use the DropDownList on the foreign object (DocumentCausal) instead of the foreign key (DocumentCausalID) using a custom editor template; but on the update action the passed foreign object has all the DateTime columns NULL and the ViewModel State is NOT Valid.

I attach also the new versione of my model, view and custom editor template.

0
Daniel
Telerik team
answered on 17 Jul 2015, 08:37 AM
Hello Andrea,

You should use the valuePrimitive option in order for the model to be updated correctly when the value is null e.g.
@model object
    
@(Html.Kendo().DropDownListFor(m => m)
    .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(""))
    .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"])
    .OptionLabel("Select")
    .ValuePrimitive(true)
)



Regards,
Daniel
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Andrea
Top achievements
Rank 1
Answers by
Andrea
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or