带有jQuery ajax cal HttpPostedFileBase文件的asp.net mvc获得空值

编程入门 行业动态 更新时间:2024-10-26 14:37:15
本文介绍了带有jQuery ajax cal HttpPostedFileBase文件的asp mvc获得空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 **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>'); } }); }

在上Ajax cal iam中的

正确获取名称和文件路径,但是当我们传递给控制器​​时 仅获取名称,但文件路径为空 我的HTML视图

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

推荐答案

将html更改为:

<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>

和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()是jQuery表单插件中的方法,可帮助管理表单提交过程- jQuery表单插件.

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

更多推荐

带有jQuery ajax cal HttpPostedFileBase文件的asp.net mvc获得空值

本文发布于:2023-11-15 22:54:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1598680.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   cal   jQuery   ajax   HttpPostedFileBase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!