
- 1、新建类库ExampleMethed和BlazorMerhed
- private string name = "张三";
- private string result = string.Empty;
- private BlazorMerhed merhed;
- private DotNetObjectReference<ExampleMethed> reference;
- private async Task TriggerMethod()
- {
- //两张方法结果一样
- //merhed = new BlazorMerhed(JSRuntime);
- //result = await merhed.CallHelloHelperGetHelloMessage(name);
- reference = DotNetObjectReference.Create(new ExampleMethed(name));
- result = await JSRuntime.InvokeAsync<string>("TriggerMethod", reference);
- }
- public void Dispose()
- {
- merhed?.Dispose();
- }
- public class BlazorMerhed : IDisposable
- {
- private readonly IJSRuntime _JSRuntime;
- private DotNetObjectReference<ExampleMethed> reference;
- public BlazorMerhed(IJSRuntime JSRuntime)
- {
- _JSRuntime = JSRuntime;
- }
- public ValueTask<string> CallHelloHelperGetHelloMessage(string name)
- {
- reference = DotNetObjectReference.Create(new ExampleMethed(name));
- var message = _JSRuntime.InvokeAsync<string>("TriggerMethod", reference);
- return message;
- }
- public void Dispose()
- {
- reference?.Dispose();
- }
- }
- public class ExampleMethed
- {
- public string Name { get; set; }
- public ExampleMethed(string name)
- {
- Name = name;
- }
- [JSInvokable]
- public string GetHelloMessage() => $"Hello, {Name}!";
- }
- window.TriggerMethod = (dotNetHelper) =>
- {
- return dotNetHelper.invokeMethodAsync('GetHelloMessage');
- };
评价
排名
11
文章
201
粉丝
10
评论
13
EF连接MySQL连接MySQL数据库操作中文数据乱码解决方法
剑轩 :
准确点应该是ef连接mysql
Layui插件上传图片具体步奏以及获取图片地址
风清月 : 厉害老!
Action与Func的用法-----委托
剑轩 : 可以可以
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256


欢迎加群交流技术