Asp.net mvc 将页面标记为;async=true";对于VisualStudioMVC项目

Asp.net mvc 将页面标记为;async=true";对于VisualStudioMVC项目,asp.net-mvc,node.js,visual-studio,model-view-controller,edge.js,Asp.net Mvc,Node.js,Visual Studio,Model View Controller,Edge.js,我正在使用Edge.js,以便可以从C#调用Node.js。根据链接中的文档,我将执行以下类似操作: [HttpPost] public ActionResult Input(InputModel obj) { validateInput(obj); return View(); } private async void validateInput(object obj) { var func = Edge.Func(@" return function

我正在使用Edge.js,以便可以从C#调用Node.js。根据链接中的文档,我将执行以下类似操作:

[HttpPost]
public ActionResult Input(InputModel obj)
{
   validateInput(obj);
   return View();
}

private async void validateInput(object obj)
{
     var func = Edge.Func(@"

        return function (data, callback){
            var username    =   data.username,
            email           =   data.email;

            callback(null, username);
        }

         ");

         ViewBag.Msg = (string)await func(obj);
}
但是,我得到以下运行时错误:

    Additional information: An asynchronous operation cannot be started at this time. 
Asynchronous operations may only be started within an asynchronous handler or module or during 
certain events in the Page lifecycle. If this exception occurred while executing a Page, ensure that the 
Page is marked <%@ Page Async="true" %>. This exception may also indicate an attempt to call an 
"async void" method, which is generally unsupported within ASP.NET request processing. Instead, 
the asynchronous method should return a Task, and the caller should await it.
其他信息:此时无法启动异步操作。
异步操作只能在异步处理程序或模块内或在
页面生命周期中的某些事件。如果在执行页面时发生此异常,请确保
页面已标记。此异常也可能表示有人试图调用
“async void”方法,该方法在ASP.NET请求处理中通常不受支持。相反
异步方法应该返回一个任务,调用方应该等待它。
我的问题有两个方面:

1.如何创建页面,async=true。我知道如何为web表单项目而不是MVC项目执行此操作


2.有没有更好的方法来做我想做的事情?当您看到我返回void时,可能会出现一个红旗,但是使用Edge.js的事实就是如此。尽管如此,我还是尝试在调用方法中返回一个
任务,然后返回
任务。Wait()
,但任务从未完成。

尝试了一些不同的方法后,以下解决方案对我有效

尽管我回答了自己的问题,而且这个问题看起来很琐碎,但我并没有删除这个问题,因为在web上关于Edge.js的知识并不多

   [HttpPost]
        public async Task<ActionResult> Input(InputModel obj)
        {
            ViewBag.Msg = await validateInput(obj);
            return View();
        }

        private async Task<string> validateInput(object obj)
            {
                var func = Edge.Func(@"
                    return function (data, callback){

                        var username    =   data.username,
                            email       =   data.email;

                        callback(null, username);
                    }
                ");

                return (string)await func(obj);
            }
[HttpPost]
公共异步任务输入(InputModel obj)
{
ViewBag.Msg=等待验证输入(obj);
返回视图();
}
专用异步任务validateInput(对象obj)
{
var func=Edge.func(@)
返回函数(数据、回调){
var username=data.username,
email=data.email;
回调(null,用户名);
}
");
返回(字符串)等待函数(obj);
}