Blazor.JsInterop.Dynamic
0.0.4
dotnet add package Blazor.JsInterop.Dynamic --version 0.0.4
NuGet\Install-Package Blazor.JsInterop.Dynamic -Version 0.0.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Blazor.JsInterop.Dynamic" Version="0.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Blazor.JsInterop.Dynamic --version 0.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Blazor.JsInterop.Dynamic, 0.0.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Blazor.JsInterop.Dynamic as a Cake Addin
#addin nuget:?package=Blazor.JsInterop.Dynamic&version=0.0.4
// Install Blazor.JsInterop.Dynamic as a Cake Tool
#tool nuget:?package=Blazor.JsInterop.Dynamic&version=0.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Blazor.JsInterop.Dynamic
.NET library to simplify javascript interop. Still in its experimental phase.
Usage:
Given the following simple javascript function, which creates an object:
window.createTestObject = (testArg) => {
alert("I've invoked a javascript global method from .NET with this parameter: " + testArg);
return {
actionTest: (testArg, testAction) => {
alert("I've invoked a javascript instance method from .NET with this parameter: " + testArg);
testAction();
},
funcTest: (testArg, testFunc) => {
alert("I've invoked a javascript instance method from .NET with this parameter: " + testArg);
testFunc(testArg);
},
returnObjectTest: (testArg) => {
alert("I've invoked a javascript instance method from .NET with this parameter: " + testArg);
return {
someValue: 123,
actionTest: (testArg, testAction) => {
alert("I've invoked a javascript instance method from .NET with this parameter: " + testArg);
testAction();
}
};
}
}
}
the object can be created and interacted with like so:
@inject Blazor.JsInterop.Dynamic.DynamicJsRuntime Runtime
@code {
private async Task ShowDialog()
{
// create the object using the "createTestObject" global function.
var reference = await JsRuntime.InvokeAsync("createTestObject", "example string 1");
// these can be passed as arguments to a javascript function and the callbacks will work correctly
var callbackAction = () => Console.WriteLine("callback action called");
var callbackFunc = (string x) => Console.WriteLine("callback func called with argument: " + x);
// call a method with an "action" parameter
reference.actionTest("example string 2", callbackAction);
// call a method with a "function" parameter
reference.funcTest("example string 2", callbackFunc);
// calling a method that returns a javascript object, will return another reference here
var otherReference = await reference.returnObjectTest("example string 4");
// we can call methods on this new object too
await otherReference.actionTest("example string 5", callbackAction);
// and just like the first object, we can access properties
// note: these values are currently populated on object creation and won't update if the underlying object's property values change.
var someValue = otherReference.someValue;
Console.WriteLine("property on returned object: " + someValue);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net7.0
- Microsoft.JSInterop (>= 7.0.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.