Quantcast
Channel: Httppostedfilebase always returns null when posted with jquery ajax - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Httppostedfilebase always returns null when posted with jquery ajax

$
0
0

I am developing an mvc application and want to upload file into server. At the controller when event fires the fileupload is null.And also the model.fileupload has the path. Actually am submitting my form using ajax post method.

cshtml code....

<form id="frmRegistrationDetails" method="post" enctype="multipart/form-data">
    <table>
      <tr>
         <td>
            <label>Upload File</label><input type="file" id="fileupload"  name="fileupload" />
         </td>
      </tr>
   </table>
</form>

controller code

 [HttpPost]
 public JsonResult SaveDetails(reg_up_mvc model,HttpPostedFileBase fileupload)
  {
  try
  {
    detailsRegistration registrationContext = new detailsRegistration();
    reg_up_mvc registrationDetails = new reg_up_mvc();
    registrationDetails.full_name = model.full_name;
    registrationDetails.fileupload = model.fileupload;
if (model.fileupload != null)
{
string sPath = Path.Combine(Server.MapPath("~/UploadedFilesFromRegistration"), fileupload.FileName);
fileupload.SaveAs(sPath);
registrationDetails.fileupload = sPath;
}

jquery

var data = {
        model: {
                fileupload: $('#fileupload').val()
               }
    };
     $.ajax({
        type: "post",
        data: JSON.stringify(data),
        url: "/Controller/ActionName",
        contentType: "application/json;charset=utf-8",
        success: function (response) {
                           alert("successful")
                           }
         });

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images