asp.net mvc与jquery ajax cal HttpPostedFileBase文件获取空值
**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('
Your Request Submitted Successfully
'); }, error: function (XMLHttpRequest, textStatus, errorThrown) { $("#simple-msg").html('"fail"'); } }); }
在aboveo ajax cal iam正确获取名称和文件路径,但是当我们传递给控制器只获取名称但文件路径变为null我的Html视图
input type="file" name="file" id="fileresume" value=""/> This is my controller [HttpPost] public ActionResult sendmail(string Name ,HttpPostedFileBase fileresume) { }
将您的HTML更改为:
并且js:
$("#btncareerssubmimt").click(function () { $("#formToSendEmail").ajaxSubmit({ type: "POST", success: function () { $("#simplecareers").html('
Your Request Submitted Successfully
'); }, error: function (XMLHttpRequest, textStatus, errorThrown) { $("#simple-msg").html('"fail"'); } }); }
.ajaxSubmit()
是来自jQuery Form Plugin的方法,它有助于管理表单提交过程.ajaxSubmit()
Form Plugin 。