I need to Upload all type of files using knockout js. I am using MVC 4.0 and i need to Save file separately in a folder. Once i have Uploaded File i need to show it in Grid(FileName, Date Created and Type of File).
This is my View and Included the Knockout scripts.
var ViewModel = function () {
var self = this;
self.fileInput = ko.observable();
self.fileName = ko.observable();
var Data = {
enter code here
file: self.fileInput,
FileName: self.fileName
};
self.save = function () {
//Ajax call to Insert the Employee
$.ajax({
type: "POST",
url: "/Home/FileUpload",
data: ko.toJSON(Data),
contentType: "application/json",
dataType: 'json',
//cache: false,
mimeType: "multipart/form-data",
//processData: false,
success: function () {
alert("successful");
},
error: function () {
alert("fail");
}
});
}
}
var vm = new ViewModel();
ko.applyBindings(vm);
<html>
<body>
<div>
<form method="post">
<span>File</span>
<input type="file" id="fileUpload" name="fileUpload" data-bind="file: {data: fileInput, name: fileName}" />
<input type="button" id="btnUpload" data-bind="click: save" value="Upload" formenctype="multipart/form-data" />
</form>
</div>
</body>
</html>
emphasized text
So kindly help me out since i am new to knockout.