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.
<PackageVersion Include="Blazor.JsInterop.Dynamic" Version="0.0.4" />
<PackageReference Include="Blazor.JsInterop.Dynamic" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version 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.
#:package Blazor.JsInterop.Dynamic@0.0.4
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Blazor.JsInterop.Dynamic&version=0.0.4
#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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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.