ApiController could not be found
13,423
You are missing the references in your project for those libraries. As per svdoever you can add the package Microsoft.AspNet.WebApi
through NuGet to fix this. For instructions on how to use NuGet, please click here
Author by
Shi Jie Tio
Updated on June 18, 2022Comments
-
Shi Jie Tio almost 2 years
Based on this video https://www.youtube.com/watch?v=IVvJX4CoLUY I have add the using System.Web; using System.Web.Http; but i still get the error state that apicontroller could no found, and so on, below picture is the error I face:
below is my code :
using System; using System.Linq; using System.Threading.Tasks; using System.Web; using System.Web.Http; using System.Collections.Generic; namespace UploadToServer.Server.Controllers { public class UploadsController : ApiController { [Route("api/Files/Upload")] public async Task<string> Post() { try { var httpRequest = HttpContext.Current.Request; if (httpRequest.Files.Count > 0) { foreach (string file in httpRequest.Files) { var postedFile = httpRequest.Files[file]; var fileName = postedFile.FileName.Split('\\').LastOrDefault().Split('/').LastOrDefault(); var filePath = HttpContext.Current.Server.MapPath("~/Uploads/" + fileName); postedFile.SaveAs(filePath); return "/Uploads/" + fileName; } } } catch (Exception exception) { return exception.Message; } return "no files"; } }
}
Anyone can share me ideas?
-
Shi Jie Tio about 6 yearsHi, I apply this in xamarin form
-
EvZ about 6 yearsYour Xamarin.Forms project cannot and should not contain any WEB.Api controllers. Your server side code should be in a separate project. Re-watch the youtube video.
-
Shi Jie Tio about 6 yearsHi I have follow exactly the video did but now i only get HttpContext error, any way to overcome it?
-
EvZ about 6 yearsTake a look on: stackoverflow.com/questions/10595543/…
-
Smokin Joe almost 6 yearsI'm following the Asp.NET tutorial and am getting the same issue. I'm not really sure how to fix this error based off of your post.