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

Grid EditMode.Popup Add Issue w EF Model Navigation Properties.

6 Answers 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Collin
Top achievements
Rank 1
Collin asked on 31 Oct 2017, 09:27 PM

Ok, I've got a grid like so-

 

@(Html.Kendo().Grid<Honovi.ACT.MVCCore.Models.Bond>()
      .Name( "GridBond" )
      .Columns( columns =>
      {
    
        //columns.Bound ( p => p.BondBotyNumber ).ClientTemplate ( " #= BondBotyNumberNavigation ? BondBotyNumberNavigation.BotyDesc : '' # " ).Title ( "Type" );  // works for edit but clicking add button fails
        //columns.Bound (p => p.BondBodyNumber.BodyDesc) // works for edit but clicking add button fails
         columns.Bound( p => p.BondBotyNumber ); works, but I want display the description here
      
        // Bunch of other columns
        columns.Command( command => { command.Edit(); command.Destroy(); } ).Width( 172 );
      } )
      .ToolBar( toolbar => toolbar.Create() )
       .Editable( editable => editable.Mode( GridEditMode.PopUp ).TemplateName( "_Bond" ).Window( w =>
            w.Title( "\uD83D\uDD89 Manage Bonds" ) 
            .Name( "winRate" )
            .Width( 560 )
       ) )
      .Selectable( selectable => selectable.Mode( GridSelectionMode.Single ) )
      .Pageable()
      .Sortable()
      .DataSource( dataSource => dataSource
          .Ajax()
          .PageSize( 10 )
          .Model( model => model.Id( p => p.BondGuid ) )
          .Events( events => events.Error( "error_handler" ) )
          .ServerOperation( false )
          .Read( read => read.Action( "Bonds_Grid_Read", "Bonds", new { corpGuid = Model.CorpGuid } ) )
          .Update( update => update.Action( "Bonds_Grid_Update", "Bonds" ) )
          .Create( update => update.Action( "Bonds_Grid_Create", "Bonds", new { corpGuid = Model.CorpGuid } ) )
          .Destroy( update => update.Action( "Bonds_Grid_Destroy", "Bonds" ) )
      )
)

 

The problem I'm having is with the column.  It is a navigation property on my model that is a foreign key that relates back to another model that is just an int / string that is used for a drop down.  On the grid the edit button works fine.  But when I click the add button nothing happens and I get the following js error in the console-

ReferenceError: BondBotyNumberNavigation is not defined[Learn More]  kendo.all.min.js%20line%2025%20%3E%20Function:3:66

If I comment out the offending navigation property and just use the int value (as above) the add button works and I get no error.

Note I'm using with EditMode.Popup if that matters.  Also I can post model code and such but it is pretty vanilla so I'm thinking I'm missing something more basic.

A little help!  Thanks.

 

 

 

 

 

6 Answers, 1 is accepted

Sort by
0
Collin
Top achievements
Rank 1
answered on 31 Oct 2017, 09:43 PM

here is the read query in the controller guts, I am including the BondBotyNumberNaviation...

IQueryable<Bond> data = _context.Bond
        .Include( c => c.BondBotyNumberNavigation )
        .AsNoTracking()
        .Where( m => m.BondCorpGuid == corpGuid );

 

...return DataSourceResult as JSON blah blah code left out...it works

 

0
Collin
Top achievements
Rank 1
answered on 31 Oct 2017, 09:45 PM

Also here is the linq query for the read in my controller.  It does work and not I am including the BondBotyNumberNavigation in the query...

IQueryable<Bond> data = _context.Bond
        .Include( c => c.BondBotyNumberNavigation )
        .AsNoTracking()
        .Where( m => m.BondCorpGuid == corpGuid );

return DataSourceSource to JSON blah blah blah code left out.  It works.

0
Stefan
Telerik team
answered on 03 Nov 2017, 12:39 PM
Hello, Collin,

Based on the last reply I can assume that the issue is resolved.

If I misunderstood the last post saying "it works" please let me know, provide a sample response for the Grid and I will gladly assist.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Collin
Top achievements
Rank 1
answered on 03 Nov 2017, 04:30 PM

No, the last reply was just to show how I was pulling that data, and that the data pull from the controller worked fine.  

The end fix is that you have to define your models that are EF navigation properties in your Grid's data source like so-

 .DataSource( dataSource => dataSource
          .Ajax()
          .PageSize( 10 )
          .Model( model => model.Id( p => p.BondGuid ) )
          .Events( events => events.Error( "error_handler" ) )
          .ServerOperation( false )
          .Read( read => read.Action( "Bonds_Grid_Read", "Bonds", new { corpGuid = Model.CorpGuid } ) )
          .Update( update => update.Action( "Bonds_Grid_Update", "Bonds" ) )
          .Create( update => update.Action( "Bonds_Grid_Create", "Bonds", new { corpGuid = Model.CorpGuid } ) )
          .Destroy( update => update.Action( "Bonds_Grid_Destroy", "Bonds" ) )
           .Model( model =>
            {
              model.Id( p => p.BondCorpGuid );
              // This is required for toolbar.Create() to work with BondBotyNumberNavigation
              model.Field( p => p.BondBotyNumberNavigation ).DefaultValue( new Honovi.ACT.MVCCore.Models.BondType());
            } )
      )

 

That will give you a default value for the add so there is no javascript error that causes the popup to not to fire when you click the add button.

 

Now this gets you through the door.  In your save code for EF for some reason the EF code will want to save both your primary model AND the navigation model,s usually something you don't want.  But that is an EF issue so outside of the scope of Telerik's support. You just have to alter the way you save things in your controller, essentially you create a new blank model, transfer it's non navigation and virtual properties, save that one so the navigation stuff isn't trying to be saved as well, then possible reload the navigation from the context back to the model you pass back to the view.  Sounds all convoluted but to those who are having a similar problem will get what I'm saying and work it out.

Thanks.

0
Brandon
Top achievements
Rank 2
answered on 26 Feb 2021, 01:35 AM
Thank you so much for your post Collin! I was surprisingly stuck on this issue for a couple and as usual, Telerik support was utterly useless. I've been using Telerik's components for nearly 15 years now and have even met some of the developers in Sofia. They used to have some of the best support that I've seen in the industry and it is sad to see the sharp decline which is so evident in this post where their "developers" can't even read a post and see that a problem isn't solved. They really leave we developers on our own to solve pretty much every issue that we encounter with their product.  
0
Dimo
Telerik team
answered on 26 Feb 2021, 08:20 AM

Hi Brandon, Collin,

Looking at the older messages in this thread, I have to admit that we have made a mistake. At first, we overlooked the fact that Collin's question was still pending, and then did not follow up. I do apologize for this omission and can assure you that this incident is disappointing for us as well. 

On the other hand, Brandon, I truly appreciate your continued business with us and I regret to see that your impressions are such. I see that your last support communication with us from this user account is from 2014. There seems to be another user account of yours with no support communication in it. Do you have another account that you are actively using, where you have stumbled upon sub-par service? Please let me know by posting with it here or in a private ticket. I will readily review your history.

Regards,
Dimo
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Collin
Top achievements
Rank 1
Answers by
Collin
Top achievements
Rank 1
Stefan
Telerik team
Brandon
Top achievements
Rank 2
Dimo
Telerik team
Share this question
or