.Net Razor Ajax Post Get處理

Talk is cheap,Show me the code.

.cshtml

複製代碼

  let pdata = { "weight": 50, "origin": originSel.value, "destination": destinationSel.value };
  let r = await axios.post("/search?handler=list" , pdata).catch(() => null);
  console.log(r);

複製代碼

.cs 注意參數要加【FromBody】,get的話 OnGetList

複製代碼

  public ActionResult OnPostList([FromBody]Ly.Model.FromBody.SearchRequestInfo requestInfo)
  {
    var list = _priceService.Search(requestInfo.Origin,requestInfo.Destination,requestInfo.Weight);
    return new JsonResult(list);
  }

複製代碼
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章