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
  • 1
  • 5
  • Take a look at the following: http://stackoverflow.com/questions/25106722/how-to-post-viewmodel-in-mvc-using-jquery – williamtroup Nov 28 '16 at 17:25

0 Answers0