1

How to upload file using Json/Ajax for an existing method as shown below. It passes null currently for HttpPostedFileBase. Any suggestions??

For instance

                                       $.ajax({

                                        url: '/SA/Save',
                                        type: "POST",
                                        data: JSON.stringify(data),
                                        dataType: "JSON",
                                        contentType: "application/json",

                                        success: function (d) {
                                            //check is successfully save to database
                                            if (d.status == true) {
                                                //will send status from server side
                                                alert('Successfully done.');
                                                //clear form
                                                teaching = [];
                                                department = [];
                                                res = [];
                                                $('#schoolname').val('');
                                                $('#schooladdress').val('');
                                                $('#teaching').empty();
                                                $('#department').empty();
                                                $('#res').empty();
                                            }
                                            else {
                                                alert('Failed');
                                            }
                                            $('#submit').val('Save');
                                        },
                                        error: function () {
                                            alert('Error. Please try again.');
                                            $('#submit').val('Save');
                                        }
                                    });

Controller

public JsonResult Save(SAViewModel O)

    {
        bool status = false;
        var userId = User.Identity.GetUserId();
        if (ModelState.IsValid)
        {             
                SA order = new SA
                {
                    SchoolName = O.SchoolName

                };

                foreach (var i in O.STQ)
                {
                    order.STQ.Add(i);
                }
Upriser
  • 77
  • 2
  • 13

0 Answers0