LoginSignup
1
1

More than 5 years have passed since last update.

knockout.jpからjquery ajaxでasp.net mvcのActionメソッドへ引数を複数渡すのに困った

Posted at

class ViewModel
{
ID: number = 0;
Display: string = null;
TableName: string = null;
Tensuu: number = 0;
IsChecked: boolean = false;
}

がtypescript上にあり、

    public JsonResult SaveShoubyoumeiSelect(int ID,List<string> value)
    {
        var result = false;

        return Json(result, JsonRequestBehavior.AllowGet);
    }

が、サーバー上にある。

var postdata = ko.toJS(xxxList);
var selectedID = $("#SELECTLIST").val();

    $.ajax(
        {
            type: "POST",
            url: "/ControllerName/ActionName",
            dataType: "json",
            contentType: 'application/json;utf-8',
            traditional: true,
            data: JSON.stringify({
                ID: selectedID,
                value: postdata
            }),

            timeout: 10000,
            success: function (data) { alert('OK'); },
            //error: function (error) { alert(error); },

        }
    );

postdataに ko.toJSにするのがキモ。
海外のサンプルなどでは、ko.toJSONが多いが、その場合はエラーになる。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1