如何在ASP.NET MVC中通过xmlhttprequest发送Blob数据 [英] How to send blob data through xmlhttprequest in asp.net mvc

查看:698
本文介绍了如何在ASP.NET MVC中通过xmlhttprequest发送Blob数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过Xhr发送blob数据.但是我没有在控制器中获取Blob数据

I am sending a blob data through Xhr. But i am not getting the blob data in the controller

我写的代码如下:

var url = "Home/Content"
var oReq = new XMLHttpRequest();
oReq.open("POST", url, true);
var blob = new Blob(['abc123'], {type: 'text/plain'}); 
oReq.send("data="+blob);

在控制器中,我已定义为:

In the controller i have defined like:

public ActionResult Content(string data)
{
  return Json("suc", JsonRequestBehavior.AllowGet);
}

但是我正在检索的data为空.我做错了.

But the data i am retrieving is null. What i am doing wrong.

推荐答案

客户端更改

oReq.send("data="+blob);

oReq.send(blob);

服务器端/控制器

public ActionResult Upload()
{
    var r = Request;
    byte[] ba = r.BinaryRead(r.ContentLength);
   ...
 }

JavaScript可以传输二进制数据.请参见此处.

JavaScript can transfer binary data. see here.

基本二进制数据已发送&没有名称/变量.

Basically binary data is sent & received without a name/variable.

这篇关于如何在ASP.NET MVC中通过xmlhttprequest发送Blob数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆