I have aspx file which having upload file option.
<input type="file" name="Attachment" />
On submit button i am sending request to MVC controller to save file.
self.SaveVPD = function () {
var emp = { FirstName: 'edfd', SecondName: 'dfdf' };
var data = new VPDModel(emp, self.EvidenceForm());
var jsonData = ko.toJSON(data);
var url = pageUrl + '/Save';
debugger;
$.ajax({
type: "POST",
url: url,
contentType: "application/json; charset=utf-8;",
//contentType: "multipart/form-data",
data: JSON.stringify(data),
//dataType: "json",
success: function (data) {
debugger;
if (data) {
//TODO::PP
}
else {
//TODO::PP
}
},
error: function () {
debugger;
//TODO::PP
}
});
}
My MVC controller is look like
[HttpPost]
public ActionResult Save(VPDModel vpdInfo) //, HttpPostedFileBase Attachment)
//public ActionResult Save(FormCollection collection)
{
if (ModelState.IsValid)
{
}
}
And my model is
public class VPDModel
{
public Employee Employee { get; set; }
public EvidenceForm EvidenceForm { get; set; }
}
EvedenceForm class is
public class EvidenceForm
{
//public string Attachment { get; set; }
public HttpPostedFileBase Attachment { get; set; }
}
When i send the request back to server VPDModel populate with all valid client side data without File Attachment. Its always null.
I have been to couple of article but cannot resolve it. can anyone help and let me know what am i doing wrong in it?