Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Ajax post时为Null参数_Ajax_Asp.net Mvc 3 - Fatal编程技术网

使用Ajax post时为Null参数

使用Ajax post时为Null参数,ajax,asp.net-mvc-3,Ajax,Asp.net Mvc 3,我已经找到了几个答案(例如),但它们似乎并不能解决我的问题 var result = { command: 'exportWAV', type: type }; $.ajax({ url: 'SubmitSound', type: 'Post'

我已经找到了几个答案(例如),但它们似乎并不能解决我的问题

                var result = {
                    command: 'exportWAV',
                    type: type
                };
                $.ajax({
                    url: 'SubmitSound',
                    type: 'Post',
                    data: JSON.stringify(result),
                    contentType: 'application/json; charset=utf-8',
                    success: function (msg) {
                        alert(msg);
                    }
                });
后端代码

        [HttpPost]
        public ActionResult SubmitSound(string blob)
        {
            // Create the new, empty data file.
            string fileName = AppDomain.CurrentDomain.BaseDirectory + "/Content/Sound/" + Environment.TickCount + ".wav";
            FileStream fs = new FileStream(fileName, FileMode.CreateNew);
            BinaryWriter w = new BinaryWriter(fs);

            w.Write(blob);
            w.Close();
            fs.Close();           
            return new JsonResult() { Data = "Saved successfully" };
        }
result
不为空,因为
this.postMessage=result将文件发送回客户端进行下载
w.Write(blob)
不断抱怨
blob
不能为
null

我怎样才能让它工作?谢谢您,并向您致以最诚挚的问候

请执行以下操作:

data: JSON.stringify({ blob: result}),
对于与JSON结构相同的对象,您可能需要在控制器操作中更改
字符串
参数。。。这意味着相同的属性名称

对象应该是这样的:

public class MyBlob{
  public string command {get; set;}
  public string type {get; set;}
}
因此,你的行动应该是:

 public ActionResult SubmitSound(MyBlob blob){
    //Here your action logic
 }

我看不出像
blob=result
现在
command
type
都是空的,我想我还没有深入挖掘它。谢谢你的想法