How do I send FormData to a controller? I am trying to upload an image:
$(".Replybtn").on("click", function() {
var fileData = new FormData();
var files = $(".Rfile[data-id=" + RId + "]").get(0).files;
if (files.length > 0) {
fileData.append("HelpSectionImages", files[0]);
}
$.post('/QJN/Reply/', {
__RequestVerificationToken: gettoken(),
TGID: RId,
SID: UId,
Com: cmnt
}, function(data) {
if (data == "Tagged") {
//
}
});
});
HTML
<input type="file" class="Rfile" [email protected] accept = "image/*,video/*">
Controller
[HttpPost, ValidateAntiForgeryToken, ValidateInput(enableValidation: true)]
public ActionResult Reply(string TGID, string SID, string Com)
{
var file = Request.Files["HelpSectionImages"];
if(file!=null){
}
}
.post()- does your request follow these guidelines?