Skip to main content

Posts

Showing posts from July, 2018

Blazor 0.5.0 Interop JavaScript from C# and C# to JavaScript call

Blazor provides two-way communication from JS to C# and C# to JS which is called Interop. The version upgrade to Blazor 0.5.0 changed the approach in interactions between cshtml and JS files. The newer version simplifies JS calling by avoiding pre-registration of JS function. In this article, we would see how to call a JS method by passing multiple parameters from cshtml and parameterized call from JS to cshtml. The scenario that is used in this article has a Kendo AutoComplete to search book and populate information based on the selection. An example of a call to JS from cshtml await JSRuntime.Current.InvokeAsync<string>( "searchBook.Init", "#SearchTitle", new DotNetObjectRef(this)); Takeaways from the above example: - JSRuntime.Current give environment to execute out-process JS. - InvokeAsync is a function that would allow executing the JS function. - The searchBook.Init is a JS function call, we would see it in details in the second sec