0

I'm trying to upload a file via angular.

So far I can select the file and post it from the angular end but I can't get the controller to receive the file.

this is how I post the file:

var f = new FormData();
f.append("file", file);

$http.post("/LoadFile", f); 

but I can't seem to get my controller to receive the file. I've tried all the following:

[HttpPost]
public ActionResult Upload(object file)

[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)

[HttpPost]
public ActionResult Upload(HttpRequestMessage request)

[HttpPost]
public ActionResult Upload()

If I add breakpoint to the methods the only one that gets hit is the last one.

1

1 Answer 1

1

Sorted.

I just needed to add the following the post method:

$http.post("/LoadFile", f, {
                transformRequest: angular.identity,
                headers: { 'Content-Type': undefined }
            }); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.