本文介绍了带有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获得空值
发布评论