Two classes :
public partial class MfgInwardsReceiptHeader : BaseEntity, IMfgInwardsReceiptHeader { ILookupSuppliers IMfgInwardsReceiptHeader.LookupSupplier { get => LookupSupplier; set => LookupSupplier = (LookupSuppliers)value; } public LookupSuppliers LookupSupplier { get { return GetValue(); } set { SetValue(value); } } [Key] public String ReceiptID { get { return GetValue (); } set { SetValue(value); } } } public partial class LookupSuppliers : BaseEntity, ILookupSuppliers { [Key] public Int32 SupplierID { get { return GetValue (); } set { SetValue(value); } } public String? SupplierName { get { return GetValue (); } set { SetValue(value); } } }
var IRHeader = new(MfgInwardsReceiptHeader); var supplierName = IRHeader.LookupSupplier?.SupplierName ?? "";
Forgot the razor :
<SfDataForm
Model="@IRHeader" ColumnCount="6" ColumnSpacing="20px">
<FormValidator>
<ObjectGraphDataAnnotationsValidator></ObjectGraphDataAnnotationsValidator>
</FormValidator>
<FormItems>
<FormItem Field="@nameof(IRHeader.SupplierID)" LabelText="Supplier" ColumnSpan="2"></FormItem>
<FormItem Field="IRHeader.LookupSupplier.SupplierName" LabelText="Supplier Name" ColumnSpan="2"></FormItem>
</FormItems>
</SfDataForm>
Hi Paul,
Thank you for sharing the details of your issue. We understand that you're encountering difficulties when binding to a property of a child object or a variable in your Blazor application.
Based on the provided classes and the code snippet for the SfDataForm component, We’ve reviewed your requirement and created a sample using a base class and a child class. You can find the sample at the following link:
Sample: https://blazorplayground.syncfusion.com/VZrpNLidqweeZNzo
For further reference and details on complex model validation in Blazor using Syncfusion's SfDataForm component, please refer to the documentation provided at the following link:
Documentation: https://blazor.syncfusion.com/documentation/data-form/validation#complex-model-validation
If you continue to encounter the same issue, We recommend modifying the shared sample to replicate the reported problem at our end. Please provide specific steps or details on how to reproduce the issue within the sample. Additionally, if possible, could you please provide a video illustration demonstrating the problem? This will help us better understand the issue and provide an accurate solution. Thank you for your cooperation.
Regards,
Yohapuja S
I have modified your sample code and have two questions :
Also, what is your recommended approach to binding to a nullable navigation property?
For example :
<FormItem Field="CreateClient.ClientAddress.Street" ColumnSpan="1" Placeholder="Address"></FormItem>
What if ClientAddress is null?
I suppose the same question could be asked of SfTextBox and other UI components too - what do you recommend when binding to a nullable navigation entity/property?
Hi Paul,
We have considered the reported issue “Console error occurs, when assigning value to the fields of the Dataform in the ParameterSetAsync" as a bug from our end and the fix for the issue will be included with our upcoming weekly release on March 6th, 2024.
Now you can track the status of the reported issue through the feedback below,
Feedback Link: https://www.syncfusion.com/feedback/51217/console-error-occurs-when-assigning-value-to-the-fields-of-the-dataform-in-the
Disclaimer: “Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.”
Regards,
Yohapuja S
The example makes no sense. Why is EventRegistration inheriting from address ?
If I remove the inheritance, the script crashes. The data in the example does NOT bind to the Navigation Property !
See simple example:
https://blazorplayground.syncfusion.com/LZBpZqVRIKpTVMcj
This is what is happening on my form. Navigations seem not to work ( i am on latest
25.1.35 version)
I gave up on Syncfusion's response.
To make navigation properties work I have to use a template and check for null.
For example :
<FormItem Field="@nameof(IRHeader.SupplierID)" ID="suppliername" ColumnSpan="6">
<Template>
@if (IRHeader.LookupSupplier is null)
{
<SfTextBox Readonly="true"></SfTextBox>
}
else
{
<SfTextBox @bind-Value="@IRHeader.LookupSupplier.SupplierName" Readonly="true"></SfTextBox>
}
</Template>
Hi Paul,
We would like to inform you that we have resolved the reported issue “Console error occurs, when assigning value to the fields of the Dataform in the ParameterSetAsync" in our latest version “25.1.35”. Therefore, we recommend upgrading to our latest version to resolve the current issue.
Rootcause:
The conflicts arise due to the complex model structure and inheritance hierarchy, where both child and parent classes inherit properties from a single base class. These conflicts occur when manipulating property values directly and indirectly through nested objects using setvalue and getvalue methods. Introducing constant and property expressions exacerbates these conflicts, requiring precise object references. Resolving these conflicts entails a thorough review and refinement of object referencing and property manipulation mechanisms
Release Notes: https://blazor.syncfusion.com/documentation/release-notes/25.1.35?type=all#data-form
Regards,
Yohapuja S
Hi Paul,
Have you managed to find a workaround for this problem?
I am using version 26.1.40 but I keep getting the following error:
Error: System.NullReferenceException: Object reference not set to an instance of an object.
at Syncfusion.Blazor.DataForm.SfDataForm.GetNestedConstantExpression(Object model, String nestedPropertyName)
at Syncfusion.Blazor.DataForm.SfDataForm.<>c__DisplayClass80_0.<RenderComponent>b__0(RenderTreeBuilder builder)
at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
at Syncfusion.Blazor.DataForm.FormItems.<BuildRenderTree>b__39_3(RenderTreeBuilder __builder5)
at Microsoft.AspNetCore.Components.CascadingValue`1.Render(RenderTreeBuilder builder)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
Hi Paul,
We apologize for the delay in our response. We have reviewed the issue you've reported and thoroughly tested it based on the provided code snippet. In our tests, we did not encounter any console errors, and the component rendered correctly. Please check the attached sample for reference.
To help us better understand and address the issue, we kindly request that you modify the shared sample to replicate the problem on our end. This will enable us to replicate the issue accurately and provide you with the most appropriate solution.
Thank you for your patience and cooperation. We're committed to assisting you and resolving this issue promptly.
Regards,
Yohapuja S
The bug is not fix, i got the same problem when i try to put a complex object in my dataform model without inheritance
@using Syncfusion.Blazor.DataForm
@using System.ComponentModel.DataAnnotations
<SfDataForm ID="MyForm" Model="CreateClient" OnValidSubmit="ValidSubmithanlder">
<FormValidator>
<ObjectGraphDataAnnotationsValidator></ObjectGraphDataAnnotationsValidator>
</FormValidator>
<FormItems>
<FormGroup ColumnCount="6" ColumnSpacing="10px">
<FormItem Field="@nameof(CreateClient.FirstName)" ColumnSpan="6"></FormItem>
<FormItem Field="@nameof(CreateClient.LastName)" ColumnSpan="3"></FormItem>
<FormItem Field="@nameof(CreateClient.Email)" ColumnSpan="3"></FormItem>
</FormGroup>
<FormGroup ColumnCount="2" ColumnSpacing="10px">
<FormItem Field="@nameof(CreateClient.ClientAddress.Street)" ColumnSpan="1" Placeholder="Address"></FormItem>
<FormItem Field="@nameof(CreateClient.ClientAddress.City)" ColumnSpan="1" Placeholder="City"></FormItem>
<FormItem Field="@nameof(CreateClient.ClientAddress.State)" ColumnSpan="2" Placeholder="State"></FormItem>
<FormItem Field="@nameof(CreateClient.ClientAddress.ZipCode)" ColumnSpan="2" Placeholder="ZipCode"></FormItem>
</FormGroup>
</FormItems>
<FormButtons>
<Syncfusion.Blazor.Buttons.SfButton>Submit</Syncfusion.Blazor.Buttons.SfButton>
</FormButtons>
</SfDataForm>
@code {
private EventRegistration CreateClient;
private string myValue = "adress";
protected override async Task OnParametersSetAsync()
{
// Call base method if needed
await base.OnParametersSetAsync();
// Assuming you have an instance of EventRegistration named CreateClient
if (CreateClient == null)
{
CreateClient = new EventRegistration();
}
// Set the value of the Street field
CreateClient.ClientAddress.Street = "123 Main St";
StateHasChanged();
}
public class BaseAddress
{
[Required(ErrorMessage = "Street is required")]
[Display(Name = "Street")]
public string Street { get; set; }
[Required(ErrorMessage = "City is required")]
[Display(Name = "City")]
public string City { get; set; }
[Required(ErrorMessage = "State is required")]
[Display(Name = "State")]
public string State { get; set; }
[Required(ErrorMessage = "Zip Code is required")]
[Display(Name = "Zip Code")]
[MinLength(5, ErrorMessage = "Zip Code must be at least 5 characters")]
[MaxLength(10, ErrorMessage = "Zip Code cannot be more than 10 characters")]
public string ZipCode { get; set; }
}
public class EventRegistration
{
[Required(ErrorMessage = "Please enter your First Name.")]
[Display(Name = "First Name")]
public string FirstName { get; set; } = "Jack";
[Required(ErrorMessage = "Please enter your last name.")]
[Display(Name = "Last Name")]
public string LastName { get; set; }
[Required(ErrorMessage = "Please enter your email-ID.")]
[Display(Name = "Email ID")]
public string Email { get; set; }
[ValidateComplexType]
public BaseAddress ClientAddress { get; set; } = new BaseAddress();
}
private void ValidSubmithanlder()
{
// Handle form submission logic
}
}
Hi Etienne,
We sincerely apologize for the delay in getting back to you. We greatly appreciate your patience.
After thoroughly validating the reported issue using our latest package and the code snippet you provided, we were unable to reproduce any console errors. The validation appears to be working as expected on our end. To assist you further, we’ve attached a sample for your reference, which you can review to ensure everything aligns with your setup
To help us better understand and replicate the issue, we kindly ask if you could modify the attached sample to demonstrate the problem you're encountering. This will allow us to investigate more effectively and provide a more accurate solution.
Thank you for your cooperation and understanding. We're here to support you, so please don’t hesitate to reach out with any further details or questions.
Regards,
Yohapuja S