Hi everyone, Firstly, thanks for trying to help me out with this. I have fixed the issue. The problem was not in the controller, it was in fact the view. My problem is I am completely new to this type of coding, In fact, up to a couple of months ago, the only programming I had dabbled in was matlab for scientific analysis purposes. I probably should spend more time learning the basics, but as I have absolutely no patience, I have decided to build first and analyse later. I would appreciate it if I could get some help understanding where I went wrong. The view I was using was utilizing Ajax. Data was added to the form data collection and then passed to the controller via Ajax call. The View:
@{
ViewBag.Title = "Upload";
}
Upload
$(document).ready(function () {
$(‘#btnUploadFile’).on(‘click’, function () {
var data = new FormData();
var files = $("#fileUpload").get(0).files;
// Add the uploaded image content to the form data collection
if (files.length > 0) {
data.append("UploadedImage", files\[0\]);
}
// Make Ajax request with the contentType = false, and procesDate = false
var ajaxRequest = $.ajax({
type: "POST",
url: "",
contentType: false,
processData: false,
data: data
});
ajaxRequest.done(function (xhr, textStatus) {
// Do other operation
});
});
});
@Html.ActionLink("Documents", "Downloads")
@TempData\["msg"\]
I had a feeling (Uneducated guess!)that using the Ajax request was the problem so I changed my approach. I used the Html.BeginForm() extension method I changed my view to:
@using (Html.BeginForm("UploadFiles", "CIsAdmin", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
}
@Html.ActionLink("Documents", "Downloads")
@TempData\["msg"\]
Can someone explain in simple terms, what the issue was? FYI, this is my controller code:
public ActionResult UploadFiles(int? id,string msg)