2
**Jquery Ajax call sending data to controller**

$("#btncareerssubmimt").click(function () {
        var Name = $("#txtname").val();
 var file = $("#fileresume").val();
 $.ajax({
                type: "POST",
                url: '/Footer/sendmail',              
                data: { Name: Name ,file: file },
                success: function () {

                    $("#simplecareers").html('<p style="color:#74ac12;margin-left:19%;">Your Request Submitted Successfully</p>');
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {

                    $("#simple-msg").html('<pre>"fail"</pre>');

                }
            });
}

in aboveo ajax cal iam getting name and file path correctly but when we pass to controller getting name only but file path getting null My Html view

 <input type="text" name="txtname" id="txtname" class="form-control" value=""/>
input type="file" name="file" id="fileresume"  value=""/>
 <input type="submit" value="Upload" id="btncareerssubmimt" class="submit" />


This is my controller

  [HttpPost]
        public ActionResult sendmail(string Name ,HttpPostedFileBase fileresume)
        {
}
user2377806
  • 53
  • 1
  • 2
  • 7

1 Answers1

2

Change your html to:

<form id="formToSendEmail" action="/Footer/sendmail">
   <input type="text" name="Name" id="txtname" class="form-control" value=""/>
   <input type="file" name="fileresume" id="fileresume"  value=""/>
   <input type="button" value="Upload" id="btncareerssubmimt" />
</form>

And js:

$("#btncareerssubmimt").click(function () {
   $("#formToSendEmail").ajaxSubmit({
               type: "POST",
               success: function () {
                   $("#simplecareers").html('<p style="color:#74ac12;margin-left:19%;">Your Request Submitted Successfully</p>');
               },
               error: function (XMLHttpRequest, textStatus, errorThrown) {
                   $("#simple-msg").html('<pre>"fail"</pre>');
               }
           });
}

.ajaxSubmit() is method from jQuery Form Plugin which helps manage form submit process - jQuery Form Plugin.

Roman Izosimov
  • 210
  • 1
  • 9
  • Thanks for your replay i tried .ajaxSubmit() and but there is no use when ever i put .ajaxSubmit() iam getting Uncaught TypeError: Object function (e,t){return new x.fn.init(e,t,r)} has no method 'ajaxSubmit' this error – user2377806 Jan 11 '14 at 08:25
  • I edited my answer and now is more completed and more understandable. – Roman Izosimov Jan 11 '14 at 08:32
  • i followed your code -when i click on upload button iam getting Uncaught TypeError: Object [object Object] has no method 'ajaxSubmit' in firebug – user2377806 Jan 11 '14 at 08:45
  • Sorry i was shure that `.ajaxSubmit()` is part of jQuery, but is part of jQuery Form Plugin - which simplifies submit forms. – Roman Izosimov Jan 11 '14 at 09:01
  • is there any code regarding sending a attachment file to controller can you help me using only ajax call with out using forms – user2377806 Jan 11 '14 at 09:21
  • please look this thread [jQuery Ajax File Upload](http://stackoverflow.com/questions/2320069/jquery-ajax-file-upload) to understand ajax file upload process – Roman Izosimov Jan 11 '14 at 09:52