Grid MVC Destroy with FK and EF code first approach help

2 posts, 0 answers
  1. Pierre
    Pierre avatar
    257 posts
    Member since:
    Apr 2007

    Posted 27 Sep 2018 Link to this post

    Hi there,

    I got 2 EF Code first tables

    public class ActionGES
     {
            public int ActionGESID { get; set; }
            [MaxLength(250)]
            public string TitreAL { get; set; }
            [Required]
            public string Description { get; set; }
     
            //FK
            public ICollection<IndicateurAction> Indicateurs { get; set; }
    }
     
    public class IndicateurAction
    {
            public int IndicateurActionID { get; set; }
            [Required]
            public int Indicateur { get; set; }
            [Required]
            public int Annee { get; set; }
            public bool ApprouveEA { get; set; }
     
            //FK Key       
            public int ActionGESId { get; set; }
            [ScriptIgnore]
            public ActionGES ActionGES { get; set; }
    }

    work good with LINQ with .include

    My question is: it is normal that when I call Destroy on my grid, I ActionGES object are created in the controller action with FK Indicateurs collection count = 1 but with en [0] item = null...

    My Controller action

    //POST: Actions_Destroy
    [Authorize]
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Actions_Destroy([DataSourceRequest] DataSourceRequest request, ActionGES act)
    {
        if (act != null && ModelState.IsValid)
        {
            this.actionService.DeleteAction(act);
        }
     
        return Json(new[] { act }.ToDataSourceResult(request, ModelState));
    }

     

    The "act" variable contain a Indicator with a null item. Look the picture.

     

  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2466 posts

    Posted 01 Oct 2018 Link to this post

    Hi Pierre,

    Could you please share the Grid configuration, so we could get better idea of the exact configuration? As a side note, please have in mind that the Grid is not designed to work with nested collections, but if the data is present in the Grid's DataSource, it should be passed correctly to the controller.

    Looking forward to your reply with the Grid's configuration.


    Regards,
    Konstantin Dikov
    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.
Back to Top