Domanda

Backload Example #4 code not working.

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;
    }
}

I get this error:

'Backload.Controllers.BackloadController' does not contain a definition for 'HandleRequestAsync'

To reproduce:

Using Package Manager Command

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;

Controller

// 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;
        }
    }
}

Error should occur on this line

ActionResult result = await base.HandleRequestAsync();
È stato utile?

Soluzione

The error is correct.

VS2010 with the Async CTP is not stable and certainly not recommended for production use. Please note that it is not easy to even create this development environment anymore, since the Async CTP is blocked by a number of Windows Updates.

But even if you use VS2012 (i.e., with Microsoft.Bcl.Async), this still won't work because async behavior is undefined on ASP.NET 4.

To use async on MVC, you must use ASP.NET 4.5 (or higher), and this means using VS2012.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top