Использование ajax для публикации списка свойств IFormFile в MVC Core 2 - PullRequest
0 голосов
/ 05 января 2019

У меня есть модель представления со списком свойств другой модели представления со свойством IFormFile. я хочу отправить форму с первой моделью представления и загрузить 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>
...