Hi every one
I am working with knockout js. I want to upload an image to the folder and other data save to database.
This is html code
<form method="post" enctype="multipart/form-data">
<input type="text" id="txteno" data-bind="value: $root.PersonId" disabled="disabled" />
<input type="text" id="txtename" data-bind="value: $root.PersonName" />
<input type="file" id="file" data-bind="file: {data: Photo, name: PersonPhoto, reader: someReader} " />
button data-bind="click :$root.save">Save</button>
</form>
and javascript code
var ViewModel = function () {
var self = this;
self.PersonId = ko.observable("0");
self.PersonName = ko.observable("");
self.PersonPhotourl = ko.observable("");
self.Photo = ko.observable();
someReader= new FileReader()
var PerData = {
PersonId: self.PersonId,
PersonName: self.PersonName,
Photo: self.Photo,
};
self.save = function () {
$.ajax({
type: "POST",
url: "/Person/FileUpload",
data: ko.toJSON(PerData),
contentType: "application/json",
dataType: 'json',
mimeType: "multipart/form-data",
success: function () {
alert("successful");
},
error: function () {
alert("fail");
}
});
};
};
var vm = new ViewModel();
ko.applyBindings(vm);
and my action result
public ActionResult Upload(Person item, HttpPostedFileBase files)
{
//some code
}
My image not sending to controller
Thank you