亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將復雜的鍵值參數表單視圖傳遞給mvc中的控制器?

如何將復雜的鍵值參數表單視圖傳遞給mvc中的控制器?

C#
慕萊塢森 2022-07-23 09:00:23
在將復雜的鍵值對從視圖發送到控制器時,我遇到了 ajax 問題。我寫了我的ajax查詢。除了“currentStateDatas”之外,所有其他變量都正確傳遞給控制器。但是, currentStateDatas 從視圖來看是空的??刂破鳛椤癱urrentStateDatas”等待“字符串”,因為我需要它的字符串類型。我無法弄清楚問題所在。請你幫助我好嗎 ?順便說一句,“currentStateDatas”包含 json。它有太多嵌套的鍵值對。currentStateDatas = {};//some values are taken from forms.$.ajax({        url: "@Url.Action("SaveTempReport", "Report")",        type: "POST",        dataType: "json",        contentType: "application/json; charset=utf-8",        data: JSON.stringify({ "categoryIds": categoryIds, "reportName": reportName, "Description": description, "tempReportId": tempReportId, "chartState": currentStateDatas, "deparmentIds": deparmentIds}),        success: function (response) {        }    });
查看完整描述

1 回答

?
白衣染霜花

TA貢獻1796條經驗 獲得超10個贊

您的控制器等待為currentStateDatas,string但在您的 js 代碼中它是一個對象,您還應該currentStateDatas使用JSON.stringify.


$.ajax({

        url: "@Url.Action("SaveTempReport", "Report")",

        type: "POST",

        dataType: "json",

        contentType: "application/json; charset=utf-8",

        data: JSON.stringify({ "categoryIds": categoryIds, 

                               "reportName": reportName, 

                               "Description": description, 

                               "tempReportId": tempReportId, 

                               "chartState": JSON.stringify(currentStateDatas), 

                               "deparmentIds": deparmentIds}),

        success: function (response) {

        }

    });


查看完整回答
反對 回復 2022-07-23
  • 1 回答
  • 0 關注
  • 106 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號