I am wondering is it possible to update C# value in Blazor using Javascript
For example
<input type="text" @bind="TestValue" >
<input type="button" value="Change value" onclick="ChangeValueFromJs()" >
@code
{
public string TestValue {get;set;} = "init value";
}
js
function ChangeValueFromJs()
{
}
Is there a way to update TestValue and successfully bind it to text input using js ChangeValueFromJs?
I tried doing this, but it didn't seem to work
function ChangeValueFromJs()
{
DotNet.invokeMethodAsync("BlazorApp", "invokeFromJS", "ChangeValue");
}
@code
{
[JSInvokable("invokeFromJS")]
public static Task ChangeValue()
{
TestValue = "New value";
return null;
}
}

InvokeAsync(StateHasChanged)insideChangeValue()to let Blazor know something has changed and it needs to re-render.var el=document.getElementById('xyz123'); el.value = 'test value'; el.dispatchEvent(new Event('change'));wherexyz123is the id of yourinput