Backload Example #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'
重现:
- 使用 VS2010,打开新的 MVC4 项目。
- 要在 VS2010 中启用异步,请安装 VS Async CTP:http ://www.microsoft.com/en-us/download/details.aspx?id=9983
- 在您的项目中,参考:[VS Async CTP Install]\Microsoft Visual Studio Async CTP\Samples\AsyncCtpLibrary.dll
使用包管理器命令
Install-Package Backload
- 下载示例:https ://github.com/blackcity/Backload
- 打开 Example #4 并从 FileUploadController.cs 复制 FileUploadDerivedController 类的代码。
用途
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();