第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

如何在 MVC 主控制器中將 http post 請求數(shù)據(jù)讀取為 JSON?

如何在 MVC 主控制器中將 http post 請求數(shù)據(jù)讀取為 JSON?

C#
拉丁的傳說 2022-07-23 17:50:00
我在下面有一個家庭控制器方法,它是從 http post 請求調(diào)用的。我需要讀取請求數(shù)據(jù)并將其發(fā)送到視圖。有沒有辦法查看原始數(shù)據(jù)而不在 SaveResponse() 中創(chuàng)建參數(shù)?感謝您的任何建議。 public ActionResult SaveResponse()    {        //Read the http post request body as json and send it to view        //HttpContext.Request.RequestContext        return View("CallbackView");    }請求正文將采用 JSON 格式。{   "customers":  {    "firstName": "Test”,    "lastName": “Lastname”,    "fullAddress":     {        "streetAddress": "123 springs lane",        "city": "New York",        "state": "NY",        "postalCode": 10021    }  }}
查看完整描述

1 回答

?
UYOU

TA貢獻(xiàn)1878條經(jīng)驗(yàn) 獲得超4個贊

你可以通過閱讀來做到這一點(diǎn)Request.InputStream


[HttpPost]

public ActionResult SaveResponse()

{

    string json;

    using (var reader = new StreamReader(HttpContext.Request.InputStream))

    {

        json = reader.ReadToEnd();

    }


    return View("CallbackView");

}

或者您可以接受string參數(shù),模型綁定器將為您完成所有工作,但您需要通過json參數(shù)將數(shù)據(jù)作為字符串傳遞。一些可用的選項(xiàng)


設(shè)置Content-Type: application/json和有效載荷{"json": "{id:44}"}


設(shè)置Content-Type: x-www-form-urlencoded和有效載荷json={id:44}


行動


[HttpPost]

public ActionResult SaveResponse(string json)

{

    return View("CallbackView");

}


查看完整回答
反對 回復(fù) 2022-07-23
  • 1 回答
  • 0 關(guān)注
  • 124 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號