1

I have a model class

public class ViewModel
{
    public HttpPostedFileBase File {get;set;}
    public string FileName {get;set;}
}

Controller

 [HttpPost] 
    public ActionResult Upload(ViewModel model)
    {
    }

VIEW

$("#myform").on("submit", function (event) {                
                event.preventDefault();
var formData = {
                    FileName: $('#fileName').val(),
                    File: $('#file').get(0).files[0],
                };
                $.ajax({
                    url: url,
                    type: "POST",
                    data: formData,
                    contentType:"multipart/form-data",
                    success: function (resp) {
}
});

I am not able to post my model to the controller? What am i doing wrong?

VineetUnchained
  • 61
  • 1
  • 2
  • 5

0 Answers0