Backload示例#4代码无法正常工作。
public class FileUploadDerivedController : BackloadController
{
// Since version 1.9 you can call the asynchronous handler method
public async Task<ActionResult> FileHandler()
{
// Call base class method to handle the file upload asynchronously
ActionResult result = await base.HandleRequestAsync();
return result;
}
}
我收到此错误:
'Backload.Controllers.BackloadController' does not contain a definition for 'HandleRequestAsync'
重现:
使用程序包管理器命令
Install-Package Backload
usings
using Backload.Controllers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Backload;
using System.Threading.Tasks;
控制器
// Change namespace to yours
namespace Backload.Examples.Example04.Controllers
{
// For all demos below open the file ~/Scripts/main.js and
// change the url of the ajax call for the fileupload plugin
// Demo 1: Derive from BackloadController and call the base class
public class FileUploadDerivedController : BackloadController
{
// Since version 1.9 you can call the asynchronous handler method
public async Task<ActionResult> FileHandler()
{
// Call base class method to handle the file upload asynchronously
ActionResult result = await base.HandleRequestAsync();
return result;
}
}
}
此行应出现错误
ActionResult result = await base.HandleRequestAsync();
答案 0 :(得分:1)
错误是正确的。
使用Async CTP的VS2010不稳定,当然不建议用于生产。请注意,甚至不再容易创建此开发环境,因为Async CTP被许多Windows更新阻止。
但即使你使用VS2012(即使用Microsoft.Bcl.Async),这仍然无效,因为async
behavior is undefined on ASP.NET 4。
要在MVC上使用async
,必须使用ASP.NET 4.5(或更高版本),这意味着使用VS2012。