티스토리 뷰

728x90
반응형
@rendermode InteractiveServer
@inject IJSRuntime JSRuntime

<button @onclick="SaveNewWord" class="btn btn-primary me-2">Save Changes</button>

<script type="text/javascript">
    window.myJsFunction = (queryResult) => {
        alert(`queryResult = ${queryResult}`);
    };
    
    function Test() {
    
    }
</script>

@code {
    private async Task SaveNewWord()
    {
    	try
     	{
         	await JSRuntime.InvokeVoidAsync("myJsFunction", "some message");
            // await JSRuntime.InvokeVoidAsync("Test");
     	} catch (JSException ex)
     	{
         	Console.WriteLine(ex.Message);
     	}
    }
}
728x90
반응형