Category : blazor-server-side

I am working on a Blazor server project and have this button in my component <button type="button" class="btn btn-primary" @onclick="@GetUserInput">Add Name</button> Here is the code I have that the click event is calling protected async void GetUserInput() { var result = await JsRuntime.InvokeAsync<string>("getName"); } function getName() { var retVal = prompt("Enter Name : ", "name ..

Read more

I tried these two events but all of them working fine on windows but not on ipad,iphonme window.onbeforeunload= function ($event) { debugger; var value=localStorage.getItem("test"); $.get("url", function () { }); }; window.onpagehide = function ($event) { debugger; var value=localStorage.getItem("test"); $.get("url", function () { }); }; Source: Ask Javascript..

Read more

I wrote a small razor class library which implements a custom component for CKEditor 5. Since the editor is displayed via JavaScript, I need to remove it in the DisposeAsync event from the component. Here is my interop implementation: export function setup(id, dotNetReference) { var newEditor = null; ClassicEditor .create(document.querySelector(‘#ckeditor-‘ + id), { toolbar: { ..

Read more

I need to get the IP address of the client, so I did the following: Created a controller and added this action: [HttpGet("[action]")] public ActionResult IpAddress() { var remoteIpAddress = HttpContext.Connection.RemoteIpAddress; if (remoteIpAddress != null) return Ok(remoteIpAddress.ToString()); return new EmptyResult(); } Added the following script to my site.js: window.getIpAddress = () => { return fetch(‘/api/utils/ipaddress’) ..

Read more

When creating a Razor Class Library in the latest Visual Studio 2019 for my Blazor server-side solution, I see the following files: ExampleJsInterop.cs public class ExampleJsInterop : IAsyncDisposable { private readonly Lazy<Task<IJSObjectReference>> moduleTask; public ExampleJsInterop(IJSRuntime jsRuntime) { moduleTask = new(() => jsRuntime.InvokeAsync<IJSObjectReference>( "import", "./_content/MyNamespace/exampleJsInterop.js").AsTask()); } public async ValueTask<string> Prompt(string message) { var module = await ..

Read more