简体   繁体   English

CS7036 C# 如何解决错误按钮 onclick

[英]CS7036 C# How to solve error button onclick

I'm using blazor project.我正在使用 blazor 项目。 I'm trying to import JavaScript function in onclick.我正在尝试在 onclick 中导入 JavaScript function。

Error CS7036 There is no argument given that corresponds to the required formal parameter 'element' of 'Index.AddDB(ElementReference, int)'错误 CS7036 没有给出与 'Index.AddDB(ElementReference, int)' 的所需形式参数 'element' 相对应的参数

Line of error (onclick)错误行(onclick)

<button class="btn btn-primary" style="width:100%" @onclick="()=>AddDB()">Calculate</button>

C# C#

    string name = string.Empty;
IJSObjectReference module;
private ElementReference InNumberPatient;
private ElementReference InInterval;
private ElementReference InMHCProduct;
private ElementReference InComProduct;
private ElementReference InMHCTreatmentTime;
private ElementReference InComTreatmentTime;
private ElementReference InMHCDaysPerDressing;
private ElementReference InComDaysPerDressing;
private ElementReference InMHCLabourTime;
private ElementReference InComLabourTime;
private ElementReference InMHCDressingCost;
private ElementReference InComDressingCost;
private ElementReference InMHCOtherCost;
private ElementReference InComOtherCost;
private ElementReference InMHCLabourCost;
private ElementReference InComLabourCost;

async Task AddDB(ElementReference element)
{
    module = await JSRuntime.InvokeAsync<IJSObjectReference>("import", "./scripts/IndexedDB.js");
    await module.InvokeVoidAsync("IndexedDb", element);
    

}
<button class="btn btn-primary" style="width:100%" @onclick="()=>AddDB()">Calculate</button>

You should pass a parameter of type ElementReference to the AddDB method, like that:您应该将 ElementReference 类型的参数传递给 AddDB 方法,如下所示:

@onclick="()=>AddDB(elementX)"

Note: the parameter elementX is of ElementReference type, defined in your code.注意:参数elementXElementReference类型,在您的代码中定义。 It is accepted as ElementReference element in your AddDB method它在您的AddDB方法中被接受为ElementReference element

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM