# Problems with context definition in nested templates

**URL:** <https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241>\
**Category:** Blazor Server\
**Created:** [April 13, 2020, 2:56pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241 "2020-04-13T14:56:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan](https://forum.radzen.com/user_avatar/forum.radzen.com/ivan/32/2893_2.png) [@Ivan](https://forum.radzen.com/u/Ivan)\
**Post date:** [April 13, 2020, 2:56pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/1 "2020-04-13T14:56:45Z")

</div>

Hello Radzen Dev Team!  
There seems to be a problem with the context definition with many child entities.  
Here is a simple example:  
Parent table:  
int: Id  
int: Value

Child1  
int Id  
int ParentId (related to parent's Id)

Child 2  
int Id  
int ParentId (related to parent's Id)

Creating Master/Hierarchy Grid:

 ![Снимок экрана 2020-04-13 в 17.39.35](https://forum.radzen.com/uploads/default/original/2X/0/051f950faa9c52a9f642681204b77eb3426a953a.png)

Let's look into Parent's template.

 ![Снимок экрана 2020-04-13 в 17.45.23](https://forum.radzen.com/uploads/default/original/2X/d/d827bd735d2069b64b259505cfa0dc4b069876f7.png)  
The application does not compile and returns an error:  
dotnet: Pages / Parent.razor (54,137): error CS0103: The name 'testModelsDataChild1' does not exist in the current context [/Users/domivan/Documents/Radzen/Test/server/Test.csproj]

Code:

 ![Снимок экрана 2020-04-13 в 17.59.56](https://forum.radzen.com/uploads/default/original/2X/1/10ae0e83ab398582aea826687e302573743dc126.png)

I understand that the context always gets the value from the previous context used.  
So, the second Add button in template belongs to the previous context from grid1

How to redefine the context for the second Add button so that it belongs to the parent context?

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [April 13, 2020, 3:14pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/2 "2020-04-13T15:14:48Z")

</div>

Reproduced! I'll post more info about fix or workaround in this thread.

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [April 13, 2020, 3:28pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/3 "2020-04-13T15:28:16Z")

</div>

The workaround is to define the child grids using string template similar to this thread:

> [@Nest Detail Records in Master Record Row?](https://forum.radzen.com/t/nest-detail-records-in-master-record-row/2947/9):
>
> Thanks! I was able to reproduce it locally - we will do our best to release fix with our next update (early next week). In the meantime you can add the detail grid as template string:

---

<div class="post-metadata">

**Author:** ![Ivan](https://forum.radzen.com/user_avatar/forum.radzen.com/ivan/32/2893_2.png) [@Ivan](https://forum.radzen.com/u/Ivan)\
**Post date:** [April 13, 2020, 3:36pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/4 "2020-04-13T15:36:10Z")

</div>

This will work for the grid, but what about the add records button?

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [April 13, 2020, 3:38pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/5 "2020-04-13T15:38:17Z")

</div>

The button(s) and the child grid(s) are part of the same template.

---

<div class="post-metadata">

**Author:** ![Ivan](https://forum.radzen.com/user_avatar/forum.radzen.com/ivan/32/2893_2.png) [@Ivan](https://forum.radzen.com/u/Ivan)\
**Post date:** [April 13, 2020, 3:47pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/6 "2020-04-13T15:47:37Z")

</div>

I understood. But this is not an option - my template is not one nested table, but an accordion with many items, nested tables, buttons, and so on.  
Suggest manually write markup? And then why was the license purchased?

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [April 13, 2020, 3:49pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/7 "2020-04-13T15:49:29Z")

</div>

I don’t have any other workarounds until the bug is fixed. The fix will be released most probably before the end of this week.

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [April 13, 2020, 3:59pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/8 "2020-04-13T15:59:29Z")

</div>

Just to add some words about the license. Radzen is complex tool and in rapidly changing environment like Angular and Blazor (several major versions in less than a year) there are chances something to not work properly. The license guarantees you that your case will be verified carefully, you will receive an answer (24h response time), we will offer you workaround and we will release fix for your problem usually in the same week.

---

<div class="post-metadata">

**Author:** ![Ivan](https://forum.radzen.com/user_avatar/forum.radzen.com/ivan/32/2893_2.png) [@Ivan](https://forum.radzen.com/u/Ivan)\
**Post date:** [April 14, 2020, 1:16pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/9 "2020-04-14T13:16:18Z")

</div>

Last fix 2.45.13 only partially solved the problem.  
Now the context of the child elements belongs to the parent, but only if element is in the root of the template.  
If the elements are placed in other containers (cards, accordion), then the value from the last used context is still taken.

This works perfectly:

 ![Снимок экрана 2020-04-14 в 16.23.21](https://forum.radzen.com/uploads/default/original/2X/d/d393fe831c495d5af08513909debb30ed05c87e8.jpeg)  
But this is not:  
 ![Снимок экрана 2020-04-14 в 16.24.52](https://forum.radzen.com/uploads/default/original/2X/f/f83086373cdc93624d3b0a4158831d09655e46a7.jpeg)

The add click button's event args from child2 try to pass context from child1 but not from template's root

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [April 15, 2020, 7:30am UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/10 "2020-04-15T07:30:21Z")

</div>

Fixed and it will be included in the next update.

---

<div class="post-metadata">

**Author:** ![Ivan](https://forum.radzen.com/user_avatar/forum.radzen.com/ivan/32/2893_2.png) [@Ivan](https://forum.radzen.com/u/Ivan)\
**Post date:** [April 15, 2020, 2:47pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/11 "2020-04-15T14:47:05Z")

</div>

2.46.0 Problem is not fixed, if the elements are placed in other containers (fieldset, cards, accordion etc), then the value from the last used context is still taken.

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [April 15, 2020, 3:15pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/12 "2020-04-15T15:15:18Z")

</div>

I have the following and it seems to work:

 ![image](https://forum.radzen.com/uploads/default/original/2X/7/72a337af2debe801aa778264b7dd2cb0194a6391.png)  
 ![image](https://forum.radzen.com/uploads/default/original/2X/e/e2cb4899a100a9ae1a9fdbf26eb76a0cd9fdfe9f.png)

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [April 15, 2020, 3:19pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/13 "2020-04-15T15:19:31Z")

</div>

@Ivan you can send us your test application to [info@radzen.com](mailto:info@radzen.com) and we will troubleshoot.

---

<div class="post-metadata">

**Author:** ![Ivan](https://forum.radzen.com/user_avatar/forum.radzen.com/ivan/32/2893_2.png) [@Ivan](https://forum.radzen.com/u/Ivan)\
**Post date:** [April 15, 2020, 3:47pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/14 "2020-04-15T15:47:27Z")

</div>

Place each group of Header, Button and Grid into different Cards or into accordion's items and error will be occurs  
[Image](https://forum.radzen.com/uploads/default/original/2X/f/f83086373cdc93624d3b0a4158831d09655e46a7.jpeg)  
[ProjectSample](https://drive.google.com/file/d/1rIemh7A4RjqLx57KRsBU2OmRXGY31RER/view?usp=sharing)

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [April 15, 2020, 4:13pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/15 "2020-04-15T16:13:14Z")

</div>

There is no problem with Cards:

 ![image](https://forum.radzen.com/uploads/default/original/2X/f/f4923be84fe082e999b334e882f6a2913c28645c.png)  
 ![image](https://forum.radzen.com/uploads/default/original/2X/4/42d080fad1608faa8b14934dda7f0589dd24c902.png)  
 ![image](https://forum.radzen.com/uploads/default/original/2X/c/cb5f4f09ba06004ec9546aade720c44554ec3ba6.png)

I cannot run your app since a lot of code is missing, still I'll try to nest the child tables in Accordion items

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [April 15, 2020, 4:20pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/16 "2020-04-15T16:20:57Z")

</div>

Ok. I was able to reproduce the error and I'll post here link to latest unofficial build when ready.

---

<div class="post-metadata">

**Author:** ![Ivan](https://forum.radzen.com/user_avatar/forum.radzen.com/ivan/32/2893_2.png) [@Ivan](https://forum.radzen.com/u/Ivan)\
**Post date:** [April 15, 2020, 4:23pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/17 "2020-04-15T16:23:49Z")

</div>

Thanks so much!  
Really, nested cards works normally, but accordion isnt

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [April 15, 2020, 4:24pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/18 "2020-04-15T16:24:32Z")

</div>

And already fixed:

 ![image](https://forum.radzen.com/uploads/default/original/2X/f/fbdcff52bccca798a111cf32787ad39db4efd687.png)

Build will be ready in several minutes.

---

<div class="post-metadata">

**Author:** ![joshbooker](https://forum.radzen.com/user_avatar/forum.radzen.com/joshbooker/32/12624_2.png) [@joshbooker](https://forum.radzen.com/u/joshbooker)\
**Post date:** [April 15, 2020, 4:45pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/19 "2020-04-15T16:45:56Z")

</div>

Does this fixed the problem when I expand a child and then click edit on another child the edit event seems to fail?

 ![image](https://forum.radzen.com/uploads/default/original/2X/9/9151ea3389fbe3c85d099349fb75ba70e3a550bb.png)

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [April 15, 2020, 4:47pm UTC](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241/20 "2020-04-15T16:47:54Z")

</div>

@joshbooker not sure if this is related - the problem in this thread is compilation error

[Next page](https://forum.radzen.com/t/problems-with-context-definition-in-nested-templates/3241.md?page=2)
