Wednesday 5 June 2019

jquery - Upload image with ajax, HttpPostedFileBase is null Mvc Asp




I must upload image before Form is submitted. So I used ajax to do it.




Here is my HelpController:



[HttpPost]
public void AcceptUpload(HttpPostedFileBase TemporaryForLast, string ReferanceNo)
{
TemporaryForLast.SaveAs(Server.MapPath("~/Profiles/images/" + ReferanceNo + "/") + "HoldCopy" + ".jpg");
}



Here is my view:






Ans Script:



$("#acceptUpload").click(function () {
var formData= new FormData();
var imagefile=document.getElementById("HoldCopy").files[0];

formData.append("imageFile",imageFile);
var xhr = new XMLHttpRequest();
xhr.open("POST", "/Help/AcceptUpload", true);
xhr.addEventListener("load", function (evt) { UploadComplete(evt); }, false);
xhr.addEventListener("error", function (evt) { UploadFailed(evt); }, false);
xhr.send(formData);
});


error functions are also updated.



Answer



View





Instead of Jquery Ajax you could use





No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...