大佬教程收集整理的这篇文章主要介绍了是否可以使用jQuery将文件从文件输入传递给控制器?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想通过传入文件,填充我的模型然后返回页面的PartialView来显示在页面上.我试过像下面的jQuery,但我永远不能让我的httpPostedFileBase正确传递(总是为null).请记住,我需要在发布后访问文件的InputStream.
var file = "files=" + $("#fileInput").files[0]; $.post("/Contacts/UploadContact/",file,function (returnHtml) { alert(returnHtml); $("#contactContainer").html(returnHtml); });
Same result can be achieved without `jquery` usage,merely you can use `XMLhttprequest` Example: **Index.cshtml** <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> <script src="@Url.Content("~/Scripts/scripts.js")" ></script> <input type="file" id="fileInput" /> <input type='button' id='go' value="go" /> $('#fileInput').on("change",function () { var xhr = new XMLhttprequest(); var VideofileS = new FormData($('form').get(0)); xhr.open("POST","/Contact/UploadContact/"); xhr.send(VideofileS); xhr.addEventListener("load",function (event) { alert(event.target.responsE); },falsE); }); });
以上是大佬教程为你收集整理的是否可以使用jQuery将文件从文件输入传递给控制器?全部内容,希望文章能够帮你解决是否可以使用jQuery将文件从文件输入传递给控制器?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。