Search code examples
c#asp.net-mvcfile-uploadvalums-file-uploader

Valums file uploader cant find my controller action


On GitHub they have asp.net mvc demo. Not full project but controller/class/binder.

I downloaded their code, there is test folder with no dependency demo and jquery demo.

I also made my controller/action as on their demo.

 public partial class UploadController : MyController
{
        [HttpPost]
        public ActionResult UploadFile(FineUpload upload, string extraParam1, int extraParam2)
        {
            // asp.net mvc will set extraParam1 and extraParam2 from the params object passed by Fine-Uploader

            var dir = @"e:\temp\";
            var filePath = Path.Combine(dir, upload.Filename);
            try
            {
                upload.SaveAs(filePath);
            }
            catch (Exception ex)
            {
                return new FineUploaderResult(false, error: ex.Message);
            }

            // the anonymous object in the result below will be convert to json and set back to the browser
            return new FineUploaderResult(true, new { extraInformation = 12345 });
        }
}

On their test demo page, i change endpoint parameter to

 endpoint: "http://localhost:60784/upload/uploadfile"

But heh, how i get exception like

A public action method 'uploadfile' was not found on controller     'MaNameSpace.Controllers.UploadController'.

Solution

  • There are two things you can do:

    1. Try adding a last slash to the endpoint URL: http://localhost:60784/upload/uploadfile/

    2. Change [HttpPost] to [HttpGet] and see if the action method gets hit.

    Using Firebug on Firefox open at the Network tab, you can take a look at the request that's being made to the server and check if the File Upload plugin is issuing a Get or Post request.