I have a Grid component that whenever I add a row manually, I get the following error:
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Unexpected character encountered while parsing value: M. Path '', line 0, position 0. Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: M. Path '', line 0, position 0. at Newtonsoft.Json.JsonTextReader.ParseValue() at Newtonsoft.Json.JsonTextReader.Read() at Newtonsoft.Json.JsonReader.ReadAndMoveToContent() at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Syncfusion.Blazor.Internal.SfBaseUtils.ChangeType(Object dataValue, Type conversionType, Boolean isClientChange, Boolean isParseValue) at Syncfusion.Blazor.DropDowns.SfDropDownBase`1[[MilGearsX.Models.ServiceHistory.Uic, MilGearsX.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetItemValue(String itemValue, Type valueType) at Syncfusion.Blazor.DropDowns.SfComboBox`2.d__51[[MilGearsX.Models.ServiceHistory.Uic, MilGearsX.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[MilGearsX.Models.ServiceHistory.Uic, MilGearsX.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext() at Syncfusion.Blazor.DropDowns.SfDropDownList`2. d__433[[MilGearsX.Models.ServiceHistory.Uic, MilGearsX.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[MilGearsX.Models.ServiceHistory.Uic, MilGearsX.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext() at Syncfusion.Blazor.DropDowns.SfDropDownList`2. d__432[[MilGearsX.Models.ServiceHistory.Uic, MilGearsX.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[MilGearsX.Models.ServiceHistory.Uic, MilGearsX.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext() at Syncfusion.Blazor.DropDowns.SfComboBox`2. d__41[[MilGearsX.Models.ServiceHistory.Uic, MilGearsX.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[MilGearsX.Models.ServiceHistory.Uic, MilGearsX.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext() at Syncfusion.Blazor.DropDowns.SfAutoComplete`2. d__48[[MilGearsX.Models.ServiceHistory.Uic, MilGearsX.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[MilGearsX.Models.ServiceHistory.Uic, MilGearsX.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext() at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
I have not been able to find any info online or otherwise that points to why this error is occurring. I have also tried debugging the component with no luck. I have attached the file in question, any help would be appreciated.
|
<EditTemplate>
@{
ServiceAssignment serviceAssignment = (context as ServiceAssignment);
if (serviceAssignment.Uic.Code == null)
{
serviceAssignment.Uic = null;
}
string personnelCategory = serviceAssignment.PersonnelCategory?.Code;
}
<SfAutoComplete PopupWidth="320px"
Placeholder="---"
@ref="UicDropDownlistRef"
TItem="Uic"
TValue="Uic"
MinLength="3"
Value="serviceAssignment.Uic"
OnInput="UicCodeChangeHandler"
DataSource="uics"
ValueChanged="uic=>serviceAssignment.Uic = uic ?? serviceAssignment.Uic"
AllowFiltering="true">
<AutoCompleteTemplates TItem="Uic">
<ItemTemplate Context="itemContext">
@{
Uic sa = (itemContext as Uic);
}
@if (!(string.IsNullOrEmpty(sa.Title) || string.IsNullOrEmpty(sa.Code)))
{
<span>@(sa.Code + " - " + sa.Title)</span>
}
else if (string.IsNullOrEmpty(sa.Title))
{
<span>@sa.Code</span>
}
else if (string.IsNullOrEmpty(sa.Code))
{
<span>@sa.Title</span>
}
</ItemTemplate>
</AutoCompleteTemplates>
<AutoCompleteEvents TItem="Uic" TValue="Uic" OnOpen="StateHasChanged" ValueChange=StateHasChanged Filtering="OnUicFilter" />
<AutoCompleteFieldSettings Text="Title" Value="Code" />
</SfAutoComplete>
</EditTemplate>
|
Thanks for the reply Berly, your solution fixed my problem! I only had to make one small change which was to add a couple of null conditional operators to account for any null reference exceptions (see code sample below). Once I did that, I was good to go, thanks again!
if (serviceAssignment?.Uic?.Code == null)
{
serviceAssignment.Uic = null;
}