0

私はいくつかの答えを見つけました(たとえばここに)が、それらは私の問題を解決していないようです。

                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" };
        }

resultthis.postMessage = result;ダウンロードのためにファイルをクライアント側に送り返すため、null ではありません。できないとw.Write(blob)不平を言い続けます。blobnull

どうすればそれを機能させることができますか?ありがとう、そしてよろしく

4

1 に答える 1

0

これを行う:

data: JSON.stringify({ blob: result}),

JSONの同じ構造を持つオブジェクトのために、コントローラーアクションでパラメーターを変更したい場合がstringあります...つまり、同じ属性名です。

オブジェクトは次のようになります。

public class MyBlob{
  public string command {get; set;}
  public string type {get; set;}
}

したがって、あなたの行動は次のようになります。

 public ActionResult SubmitSound(MyBlob blob){
    //Here your action logic
 }
于 2013-09-20T03:31:51.430 に答える