Context variable name conflict

Hello everyone. 

I am using Grid Template in Sfgrid and everything else works fine except for the compilation error I get when I try to to define an instance of Context object. I am using authentication so AthenticationStateProvider cascading parameter Context object (which is different type) conflicts the Context in the Grid Template 

The error message is shown below 
 "The child content element ' Childcontent' component 'Editform' uses the same parameter name 'context' as enclosing child content element 'Authorized' component 'Authorizeview'.... " 

Thanks in advance for your help. 

7 Replies 1 reply marked as answer

DR Dhivya Rajendran Syncfusion Team October 13, 2020 02:13 PM UTC

Hi Paul, 

Greeting from Syncfusion support. 

We have validated the provided information. We suspect that in your application you are using template inside template so that it cause the problem if so then we suggest you to Context as follows to achieve your requirement. 

Please refer the below code example for more information.  

  
@*When provide the Template inside another template, At these cases you must provide Context*@   
  
    <GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Dialog">  
        <Template>  
          @{  
                 ...  
                                                                <SfGrid TValue="IndicatorValue"...>  
                                ...  
                                <GridColumns>  
                                    <GridColumn Field="@nameof(IndicatorValue.IndicatorId)" ...>  
                                        <Template Context="GridInsideDialog">  
                                            @((context as IndicatorValue)?.Indicator?.ToString())  
                                        </Template>  
                                    </GridColumn>  
                                </GridColumns>  
                                <GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" />  
                            </SfGrid>  
                        </div>  
                    </div>  
                </div>  
            }  
        </Template>  
    </GridEditSettings>  

If the provided solution does not resolve the problem then please get back to us with gridsettings(code example) to validate further and to provide an better solution as soon as possible. 

Regards, 
R.Dhivya 



PA Paul October 14, 2020 09:50 AM UTC

Thanks so much for the prompt response.

I will implement your suggestion and get back to you ASAP


VN Vignesh Natarajan Syncfusion Team October 15, 2020 04:27 AM UTC

Hi Paul,  

Thanks for the update.  

We will wait to hear from you.  

Regards, 
Vignesh Natarajan   




PA Paul October 16, 2020 09:37 AM UTC

Thanks again for the response. 

I am not using nesting Templates. I have just one template. My code block is shown below along with the error messqge.


     <EditForm Model="@treatment">


            <div class="row">
                <div class="col-7 ">
                    <div class="group-box ">
                        <div class="form-row">

                            <div class=" col-6 form-group">
                                <SfTextBox Value="PatientCode"
                                           Placeholder="Patient Code"
                                           FloatLabelType="FloatLabelType.Always"
                                           Enabled="false"> </SfTextBox>
                            </div>


                            <div class=" col-6 form-group">
                                <SfTextBox Value="FullName"
                                           Placeholder="Patient Name"
                                           FloatLabelType="FloatLabelType.Always"
                                           Enabled="false"> </SfTextBox>
                            </div>

                            @* diagnoses *@
                            <SfGrid DataSource="@GetDiagnoses"
                                        Toolbar="@(new string[] {"Add", "Edit" ,"Delete","Update","Cancel" })">

                                    <GridEvents TValue="DiagnosesForDetailsDto"
                                                OnActionBegin="OnActionBeginHandler"></GridEvents>

                                    <GridEditSettings AllowAdding="true"
                                                      AllowEditing="true"
                                                      AllowDeleting="true"
                                                      Mode="EditMode.Dialog">

                                        <Template>

                                            @{
                                                var diagnos = (context as DiagnosesForDetailsDto);

                                                <div>

                                                    <div class="form-row">
                                                        <div class="form-group col-md-6">

                                                            <SfNumericTextBox @bind-Value="@(DiagnosesForDetailsDto.Id)"
                                                                              Enabled="@IsAddNew"
                                                                              Placeholder="Order ID"
                                                                              FloatLabelType="FloatLabelType.Always"
                                                                              TValue="int?"></SfNumericTextBox>

                                                        </div>

                                                        <div class="form-group col-md-6">

                                                            <SfAutoComplete DataSource="@GetDiagnoses"
                                                                            TItem="DiagnosesForDetailsDto"
                                                                            TValue="string"
                                                                            @bind-Value="@(DiagnosesForDetailsDto.Description)"
                                                                            Placeholder="Select Diagnoses"
                                                                            FloatLabelType="FloatLabelType.Always">

                                                                <AutoCompleteFieldSettings Value="Id"></AutoCompleteFieldSettings>
                                                            </SfAutoComplete>

                                                        </div>
                                                    </div>

                                                </div>
                                                }

                                        </Template>

                                    </GridEditSettings>

                                    <GridColumns>
                                        <GridColumn Field="Id"
                                                    HeaderText="Order ID"
                                                    TextAlign="TextAlign.Right"
                                                    Width="120"
                                                    IsPrimaryKey="true">
                                        </GridColumn>
                                        <GridColumn Field="Code"
                                                    HeaderText="Code"
                                                    Width="150">
                                        </GridColumn>
                                        <GridColumn Field="Description"
                                                    HeaderText="Description"
                                                    Width="150">
                                        </GridColumn>
                                    </GridColumns>

                                </SfGrid>

                        </div>
                    </div>
                </div>
            </div>

            <input type="submit" class="form-control col-1 btn btn-primary mt-1" value="Save" />


        </EditForm>
@code {


    public void OnActionBeginHandler(ActionEventArgs<DiagnosesForDetailsDto> args)
        => IsAddNew = args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Add);

}



Error message:

Severity Code Description Project File Line Suppression State
Error The child content element 'Template' of component 'GridEditSettings' uses the same parameter name ('context') as enclosing child content element 'ChildContent' of component 'EditForm'. Specify the parameter name like: '<Template Context="another_name"> to resolve the ambiguity



VN Vignesh Natarajan Syncfusion Team October 19, 2020 06:58 AM UTC

Hi Paul,  
 
Thanks for sharing the details.  
 
Query: “I am not using nesting Templates. I have just one template. My code block is shown below along with the error messqge. 
 
We have analyzed your code example and found that you have rendered the Grid (with Dialog Template) inside a Blazor EditForm. We have rendered the Grid’s DialogTemplate as Render Fragment and values needs to be sent to template using context variable. By default variable name to access values inside template will be “context”.  But since we have rendered the Grid inside EditForm, conflict occur between the EditForm context and DialogTemplate context.  
 
We suggest you to overcome the reported issue by defining the specific name to template context (i.e.) for DialogTemplate context. Refer the below code example.  
 
<EditForm Model="@treatment">> 
    <SfGrid DataSource="@GridData" Toolbar="@(new string[] {"Add""Edit" ,"Delete","Update","Cancel" })"> 
        <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="@EditMode.Dialog"> 
            <Template Context="DialogContext"> 
                @{ 
                    var Order = (DialogContext as OrdersDetails); 
                } 
            </Template> 
        </GridEditSettings> 
    </SfGrid> 
</EditForm> 
 
 
Refer our UG documentation for  your reference 
 
 
Please get back to us if you have further queries.  
 
Regards, 
Vignesh Natarajan 
 


Marked as answer

PA Paul October 20, 2020 12:05 AM UTC

Thanks so much. It worked like magic. 

Thanks once again


VN Vignesh Natarajan Syncfusion Team October 20, 2020 03:39 AM UTC

Hi Paul,  

Thanks for the update.  

We are glad to hear that you have resolved your query using our solution.  

Please get back to us if you have further queries.  

Regards, 
Vignesh Natarajan 


Loader.
Up arrow icon