I have a personal learning Blazor Wasm app in which I am using JS Interop to invoke a JavaScript function from a Blazor method. I instantiate in the Blazor method an object whose properties have capitalized names and then pass that object to the JS function
as shown in the code below. Curiously, when I inspect and use the object in the JS code, the property names have lost their capitalization. Is that supposed to happen? I pray I am not doing something stupid to make this happen, but at this stage of my learning,
that wouldn't be a big surprise.
Thanks. Steve
public class MyClass
{
// Note that if this doesn't match the json object, no error is thrown
public string BBName { get; set; }
public string BBTName { get; set; }
public int Year { get; set; }
public string VblName { get; set; }
public int Nature { get; set; }
public int Format { get; set; }
public int Flags { get; set; }
public decimal DecValue { get; set; }
public string StringValue { get; set; }
public MyClass() { }
public MyClass(string bbName, string bbtName, int year, string vblName, int nature, int format, int flags, decimal decValue, string stringValue)
{
BBName = bbName;
BBTName = bbtName;
Year = year;
VblName = vblName;
Nature = nature;
Format = format;
Flags = flags;
DecValue = decValue;
StringValue = stringValue;
}
}
private async Task passMyObject()
{
MyObject obj = new MyClass("bbName", "bbtName", 2020, "vblName", 1, 2, 3, 2000.23m, "stringValue");
var text = await JSRuntime.InvokeAsync<string>("MyObject_Pass", obj);
msgResult = text;
StateHasChanged();
}
Member
26 Points
63 Posts
Property Name Capitalization Changes Across JSRuntime.InvokeAsync in Blazor Wasm App
Jun 14, 2020 08:03 PM|CincySteve|LINK
I have a personal learning Blazor Wasm app in which I am using JS Interop to invoke a JavaScript function from a Blazor method. I instantiate in the Blazor method an object whose properties have capitalized names and then pass that object to the JS function as shown in the code below. Curiously, when I inspect and use the object in the JS code, the property names have lost their capitalization. Is that supposed to happen? I pray I am not doing something stupid to make this happen, but at this stage of my learning, that wouldn't be a big surprise.
Thanks. Steve