0

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'

重现:

使用包管理器命令

Install-Package Backload

用途

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();
4

1 回答 1

1

错误是正确的。

带有异步 CTP 的 VS2010 不稳定,当然不推荐用于生产。请注意,创建这个开发环境已经不容易了,因为异步 CTP 被许多 Windows 更新阻止。

但即使您使用 VS2012(即使用 Microsoft.Bcl.Async),这仍然无法正常工作,因为async行为在 ASP.NET 4 上未定义

async在 MVC 上使用,您必须使用 ASP.NET 4.5(或更高版本),这意味着使用 VS2012。

于 2013-12-14T03:29:19.510 回答