iT邦幫忙

0

.Net Core 6.0 Array POST 至後端接不到

N3o 2023-05-12 17:21:57914 瀏覽
  • 分享至 

  • xImage

前端輸出都有值,但後端接不到參數,有大大能解惑嗎?
(雖然用字串可以往後傳,但想知道為何 Array 不行

前端 Code

var studentList = [];
$("[name='studentObj']:checked").each(function (index, obj) {
    studentList.push(obj.value);
});
this.VoucherModel.StudentList = studentList;
console.dir(this.VoucherModel);                
modal.fleeting("Running...");

await axios({
    method: 'post',
    url: '/Student/DistributedVoucher',
    headers: {
        "Content-Type": "multipart/form-data",
    },
    data: {
        Count: this.VoucherModel.Count,
        StudentList: this.VoucherModel.StudentList,
    }
}).then(async function (res) { 
    if (res.isSucess == true) { modal.alert("Success"); }
}).catch(err => {
    modal.alert("Fail:" +  err.response.data);
});

前端輸出
https://ithelp.ithome.com.tw/upload/images/20230512/20123169d3QRkMUWoE.png


後端 Code

[HttpPost]
[IgnoreAuthorize]
public async Task<IActionResult> DistributedVoucher(DistributedVoucherViewModel model)
{
    // do something ...			
    return Ok();
}
public class DistributedVoucherViewModel
{
    public List<String> StudentList { get; set; }
    public int Count { get; set; }
}

後端監測
https://ithelp.ithome.com.tw/upload/images/20230512/20123169a2Xu3YQVq5.png

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
科科
iT邦研究生 1 級 ‧ 2023-05-12 23:22:09

"Content-Type" 不要用 "multipart/form-data",
用"application/json" 試試

我要發表回答

立即登入回答