C#学习教程:如何在asp.netmvc中通过xmlhttprequest发送blob数据但是我没有在控制器中获取blob数据我写了这样的代码:varurl="Home/Content"varoReq=newXMLHttpRequest();oReq.open("POST",url,true);varblob=newBlob(['abc123'],{type:'text/plain'});oReq.send("data="+blob);在我定义的控制器中:publicActionResultContent(stringdata){returnJson("suc",JsonRequestBehavior.AllowGet);但是我检索到的数据是空的。我做错了什么。我已经解决了这个问题。您正在将二进制数据发送到mvc控制器方法,并且在该方法中您将二进制值作为字符串获取注意如果您要使用保存方法,您应该使用这是问题的主要原因varfileContent=window.btoa(blob);oReq.send(JSON.stringify({data:fileContent}));所以在你的服务器端方法byte[]fileByte=Convert.FromBase64String(fileContent);客户端更改oReq.send("data="+blob);到oReq.send(blob);服务器端组/控制器publicActionResultUpload(){varr=Request;byte[]ba=r.BinaryRead(r.ContentLength);...}JavaScript可以传输二进制数据。看这里。基本上二进制数据是在没有名称/变量的情况下发送和接收的。以上就是C#学习教程:如何在asp.netmvc中通过xmlhttprequest发送blob数据共享的全部内容。代表立场,如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
