我有一个带有IFormFile属性的另一个视图模型的属性列表的视图模型。 我想使用第一个viewmodel提交表单,并从第二个视图模型上载IFormFile
我如何使用Ajax表单上传文件
(对不起我的英语不好)
我的代码在这里:
我的视图模型:
public class VmCustomer
{
public string PhoneNumber { get; set; }
public string Keyword { get; set; }
public Guid OfficeId { get; set; }
public StaticPagedList<VmCustomerInfo> Customers { get; set; }
public SelectList Offices { get; set; }
public int? Page { get; set; }
public Guid CustomerId { get; set; }
public string CustomerFullName { get; set; }
public List<VmDocument> Documents { get; set; }
}
public class VmDocument
{
public Guid DocumentId { get; set; }
public string DocumentDescription { get; set; }
public bool IsRequired { get; set; }
public DateTime CreateDateTime { get; set; }
public IFormFile Uploaded { get; set; }
}
我的观点:
@model VmCustomer
<form asp-action="AddCustomerToOfficeAsync" id="myForm" name="myForm"
enctype="multipart/form-data">
<input type="hidden" asp-for="OfficeId" />
<input type="hidden" asp-for="CustomerId" />
@{
int count = 0;
foreach (var doc in Model.Documents)
{
<div class="alert alert-primary">
<div class="alert-heading">
<h4><i class="fal fa-id-card"></i>@doc.DocumentDescription <span class="red"> @(doc.IsRequired ? "*" : "")</span> </h4>
</div>
<input class="form-control" type="file" asp-for="Documents[count].Uploaded" required="@doc.IsRequired"/>
</div>
count++;
}
}
</form>