0

I'm trying to get the input type file value in MVC 5 C# controller but unable to get the value. I'm using bootstrap model and JQuery Ajax to do this task. And i Dont use form submit for this. following is my code.

bootstrap model code :

<div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4>Mark Chargeback</h4>
                </div>
                <div class="modal-body" align="center">
                    <div>
                        <input type="file" id="fdocs" class="form-control" style="margin-top: 5px;"/>                           
                        <input type="submit" id="btngetdocs" class="btn btn-success" value="Submit" style="margin-top: 5px;" />
                    </div>
                </div>
            </div>

JQuery Ajax code :

 $('#btngetdocs').click(function () {
            var docs = $('#fdocs').val();
            //alert(docs);
                $.ajax({
                    type: "POST",
                    url: "../CS/GetDocs",
                    data: '{checkimg:"' + docs + '"}',
                    mimeType: "multipart/form-data",
                    contentType: 'application/json',
                    dataType: "json",
                    success: function (data) {
                        alert(data);
                        $('#myModal').modal('hide');
                    },
                    error: function () {
                        alert(data);
                    }
                });
        });

MVC Controller Code :

        [HttpPost]
        public ActionResult GetDocs(HttpPostedFileBase checkimg)
        {
            try
            {
                int result = DOCs(checkimg);
                if (result > 0)
                {
                    return Json("Docs upload Successfully.");
                }
                else
                {
                    return Json("Please Try again.");
                }
            }
            catch (Exception ex) { return Json(ex.ToString()); }
        }

So please rid me out from this problem.

0 Answers0