Search code examples
javascript.netasp.net-web-apisyncfusion

Upload Image Web Api


I'm trying to add the upload box from SyncFusion to my Web App. I added the Upload Box:

<div id="targetElement">
                <div id="UploadDefault"></div>
            </div>

<script>
    $(function () {
        //Declaration
        $("#UploadDefault").ejUploadbox({
            saveUrl: "/api/project/uploadimage"
        });
    });
</script>

Then I want to add using an WebApi Controller:

[HttpPost]
        [Route("project/uploadimage")]
        public async Task UploadFile(string fileName, string description)
        {
}

But I always get the http response:

The requested resource does not support http method 'POST'


Solution

  • You're calling "/api/project/uploadimage" in your JS code whereas your attribute routing is project/uploadimage. You're also using parameters in your method, so if you want them to be passed through the url you need to add them in the Route attribute ([Route("api/project/uploadimage/{fileName}/{description}")]), otherwise you need to get them from the body, so you need to use [FromBody] attribute on your method.

        [HttpPost]
        [Route("api/project/uploadimage")]
        public async Task UploadFile([FromBody] string fileName,[FromBody] string description)
        {
        }