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)
        {
}
1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for your replay i tried .ajaxSubmit() and <input type="file" name="fileresume" id="fileresume" value=""/> 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
I edited my answer and now is more completed and more understandable.
i followed your code -when i click on upload button iam getting Uncaught TypeError: Object [object Object] has no method 'ajaxSubmit' in firebug
Sorry i was shure that .ajaxSubmit() is part of jQuery, but is part of jQuery Form Plugin - which simplifies submit forms.
is there any code regarding sending a attachment file to controller can you help me using only ajax call with out using forms
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.