FormData append item in array

后端 未结 2 1334
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 00:55
 public List Regions { get; set; }

in model called News.An Region Model is

public class Region
    {
        public i         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 01:53

    If your using FormData to send the data, you need to .append() each individual name/value to FormData. Since its a collection, you must include the collection indexer (which must be zero based and consecutive), for example

    formData.append("Regions[0].Id", someValue);
    formData.append("Regions[0].Name", someValue);
    formData.append("Regions[1].Id", someValue);
    formData.append("Regions[1].Name", someValue);
    

    Since your doing this in a loop, you can use

    for (var i = 0; i < region.length; i++) {
        formData.append("Regions[" + i + "].Id", region[i])
    }
    

提交回复
热议问题