Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
I am trying to figure out how I get dropzone.js to work with a C# based web service. But the issue I got is that I am running into a 404 error after I selected a file to upload.

These are the steps I have done: In VS2012 I started an empty MVC4 application. Then I added and index.html, dropzone.js and jquery via NuGet (don't know if dropzone needs it, just added it to be save). Based on the example on the website of dropzone.js, I wrote the next html code:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link href="CSS/FileUploader.css" rel="stylesheet" />
    <script src="Scripts/jquery-2.0.2.min.js"></script>
    <script src="Scripts/DropZone.js"></script>
    <script>

    </script>
    <title>File Uploader test</title>
</head>
<body>
    <form action="/FileUpload/FileUploadController"
          class="dropzone" <!-- this css class contains: background-color: yellow; -->
          id="my-awesome-dropzone"></form>
</body>
</html>

I added a routing to the routing config in the RouteConfig.cs like this:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.MapRoute(
        name: "FileUpload",
        url: "FileUpload/FileUploadController",
        defaults: new
        {
            controller = "FileUploadController",
            action = "FileUpload"
        }
    );
}

And my controller looks like this:

public class FileUploadController : Controller
{
    [HttpPost]
    public ActionResult FileUpload(IEnumerable<HttpPostedFileBase> files)
    {
        return null; //Breakpoint here
    }
}

I put a breakpoint on the "return null" line just to test if the method is called properly. When I run the code and open the html page, the dropzone control works properly. But when I select a file, this error is shown: The HTTP verb POST used to access path '/FileUploadController/FileUpload' is not allowed. and I cannot figure out why. Also, the code doesnt break on the break point so I guess the method isn't called properly.

What am I doing wrong here?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900