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

Grid MVC Destroy with FK and EF code first approach help

1 Answer 24 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 1
Iron
Pierre asked on 28 Sep 2018, 01:05 AM

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.

 

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 01 Oct 2018, 12:14 PM
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.
Tags
Grid
Asked by
Pierre
Top achievements
Rank 1
Iron
Answers by
Konstantin Dikov
Telerik team
Share this question
or