Inline editing nullable foreign key

3 posts, 0 answers
  1. Andrea
    Andrea avatar
    2 posts
    Member since:
    Feb 2013

    Posted 15 Jul 2015 Link to this post

    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. Andrea
    Andrea avatar
    2 posts
    Member since:
    Feb 2013

    Posted 15 Jul 2015 Link to this post

    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.

  3. Daniel
    Admin
    Daniel avatar
    2231 posts

    Posted 17 Jul 2015 Link to this post

    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
Back to Top