无法将一系列对象附加到formdata -vuejs -asp.net core
我正在尝试将一系列对象附加到FormData,但由于某种原因,我无法使其工作。看来,CreateStockingRedientdto未接收我通过的值。我一定缺少一些东西。我在这里寻找帮助。
控制器代码:
[HttpPost]
[Route("create")]
public int Create(IFormFile invoiceAttachment, [FromForm]CreateStockCommand command)
{
// do something here.
}
请求处理程序
public class CreateStockCommand : IRequest<int>
{
public DateTime CreatedDate { get; set; }
public string? SupplierInvoiceId { get; set; }
public int SupplierId { get; set; }
public ICollection<CreateStockIngredientDto>? CreateStockIngredientDtos { get; set;
}
public class CreateStockIngredientDto
{
public decimal Price { get; set; }
public decimal Quantity { get; set; }
public DateTime StockedDate { get; set; }
public DateTime ExpiryDate { get; set; }
public int IngredientId { get; set; }
}
客户端-Vuejs
const formData = new FormData()
formData.append('invoiceAttachment', invoiceAttachment.value)
formData.append('CreatedDate', createdDate.value)
formData.append('SupplierInvoiceId', supplierInvoiceId.value)
formData.append('SupplierId', supplierId.value)
formData.append('CreateStockIngredientDtos', createStockIngredientDtos.value)
axios.post('stock/create', formData, { headers: { 'Content-Type': 'multipart/form-data' } })
.then(response => {
// do something...
})
const createStockIngredientDtos = ref([{
`enter code here`ingredientId: 1, price: 200, quantity: 20, expiryDate: '2022-06-29',
}])
I'm trying to append an array of objects to FormData but I couldn't get this to work for some reason. As it appears, CreateStockIngredientDto doesn't receive values that I pass. I must be missing something. I'm looking for a helping hand here.
Controller Code:
[HttpPost]
[Route("create")]
public int Create(IFormFile invoiceAttachment, [FromForm]CreateStockCommand command)
{
// do something here.
}
Request Handler
public class CreateStockCommand : IRequest<int>
{
public DateTime CreatedDate { get; set; }
public string? SupplierInvoiceId { get; set; }
public int SupplierId { get; set; }
public ICollection<CreateStockIngredientDto>? CreateStockIngredientDtos { get; set;
}
public class CreateStockIngredientDto
{
public decimal Price { get; set; }
public decimal Quantity { get; set; }
public DateTime StockedDate { get; set; }
public DateTime ExpiryDate { get; set; }
public int IngredientId { get; set; }
}
Client Side - Vuejs
const formData = new FormData()
formData.append('invoiceAttachment', invoiceAttachment.value)
formData.append('CreatedDate', createdDate.value)
formData.append('SupplierInvoiceId', supplierInvoiceId.value)
formData.append('SupplierId', supplierId.value)
formData.append('CreateStockIngredientDtos', createStockIngredientDtos.value)
axios.post('stock/create', formData, { headers: { 'Content-Type': 'multipart/form-data' } })
.then(response => {
// do something...
})
const createStockIngredientDtos = ref([{
`enter code here`ingredientId: 1, price: 200, quantity: 20, expiryDate: '2022-06-29',
}])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于想出了。我希望它能希望其他人。
I figured it out finally. I hope it will hope someone else.