Returning the result of a javascript function to a variable in Blazor server - Stack Overflow

I have a method like below. I will like to call a javascript function and return the resultin to a var

I have a method like below. I will like to call a javascript function and return the result in to a variable

        private async Task Checker()
        {
           var result = (await JsRuntime.InvokeVoidAsync("checkNullValues");
        }

Here is the javascript function

        function checkNullValues() {
            return $('.k-grid-container .excelGridCell').length === 0 && $('.k-textbox').length == 0;
        }

In the Checker method, I kept getting this error message

"cannot implicitly convert type void to string"

Is it not possible to do this?

I have a method like below. I will like to call a javascript function and return the result in to a variable

        private async Task Checker()
        {
           var result = (await JsRuntime.InvokeVoidAsync("checkNullValues");
        }

Here is the javascript function

        function checkNullValues() {
            return $('.k-grid-container .excelGridCell').length === 0 && $('.k-textbox').length == 0;
        }

In the Checker method, I kept getting this error message

"cannot implicitly convert type void to string"

Is it not possible to do this?

Share Improve this question asked Aug 27, 2021 at 20:12 BabaBaba 2,2299 gold badges53 silver badges94 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

If you expect to receive values from Javascript function using JSInterop, you should use InvokeAsync method instead of InvokeVoidAsync, indicating the datatype expected to retrieve. For example I suppose that you want to receive a bool, so:

private async Task Checker()
{
    var result = await JsRuntime.InvokeAsync<bool>("checkNullValues");
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745088489a4610548.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信