# Sending a Model Property to the Server When Removing a File from the Upload

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Telerik UI for ASP.NET Core Upload</td>
 </tr>
 <tr>
  <td>Progress Telerik UI for ASP.NET Core version</td>
  <td>Created with the 2023.1.117 version</td>
 </tr>
</table>

## Description

I use the [Upload component in asynchronous mode](https://demos.telerik.com/aspnet-core/upload/async), and by using its `Files()` configuration, I display an initial list of files when the page loads.
How can I pass a View Model property `Id` to the server when the user removes a file from the Upload list?

## Solution

1. Populate the Ids of the initially rendered files in hidden input elements on the same View, where the Upload component is defined.

```Razor HtmlHelper
  @model UserViewModel

  @foreach(var file in Model.Files)
  {
      <input id="fileID_@file.Name" type="hidden" value="@file.Id" />
  }

  @(Html.Kendo().Upload()
        .Name("files")
        .Async(a => a
            .Save("Save", "Upload")
            .Remove("Remove", "Upload")
            .AutoUpload(true)
        )
        .Files(files =>
        {
            if(Model.Files != null)
            {
                foreach (var file in Model.Files)
                {
                    files.Add().Name(file.Name).Extension(file.Extension).Size(file.Size ?? 0);
                }
            }
        })
  )
```

```Razor TagHelper
    @addTagHelper *, Kendo.Mvc
    @model UserViewModel

    @foreach(var file in Model.Files)
    {
      <input id="fileID_@file.Name" type="hidden" value="@file.Id" />
    }
    <kendo-upload name="files">
        <async save-url="@Url.Action("Save","Upload")" remove-url="@Url.Action("Remove","Upload")"  auto-upload="true"/>
        <files>
            @{
                if(Model.Files != null)
                {
                    foreach (var file in Model.Files)
                    {
                        <file name="@file.Name" extension="@file.Extension" size="@file.Size" />
                    }
                }
            }
        </files>
    </kendo-upload>
```

```C# Model
  using Kendo.Mvc.UI;

  public class UserViewModel
  {
      public List<UploadPdfFile> Files { get; set; }
  }

  public class UploadPdfFile : UploadFile
  {
	public long Id { get; set; }
  }
```

2. Handle the `Remove` event of the Upload that triggers when an uploaded file is about to be removed. Get the `Id` of the file that will be removed from the respective hidden input, and send it to the server through the Upload Remove request.

```Razor HtmlHelper
  @model UserViewModel

  @foreach(var file in Model.Files)
  {
      <input id="fileID_@file.Name" type="hidden" value="@file.Id" />
  }

  @(Html.Kendo().Upload()
        .Name("files")
        .Events(ev => ev.Remove("onRemove"))
        ...
  )
```

```Razor TagHelper
    @addTagHelper *, Kendo.Mvc
    @model UserViewModel

    @foreach(var file in Model.Files)
    {
      <input id="fileID_@file.Name" type="hidden" value="@file.Id" />
    }
    <kendo-upload name="files" on-remove="onRemove">
        
    </kendo-upload>
```

```JS script
<script>
    function onRemove(e) {
        var fileName = e.files[0].name; // Get the name of the file that will be removed.
        var customFileId = 0;
        $.each($("input[id^='fileID_']"), function () { // Loop through the hidden inputs.
            var name = $(this).attr('id').split('_')[1]; // Extract the "Name" from the "id" attribute.
            if (name == fileName) {
                customFileId = $(this).val(); // Store the "Id" property of the file.
            }
        });
        e.data = { // Attach a data object to the passed event.
            fileId: customFileId 
        };
}
</script>
```

## More ASP.NET Core Upload Resources

* [ASP.NET Core Upload Documentation](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/editors/upload/overview)

* [ASP.NET Core Upload Demos](https://demos.telerik.com/aspnet-core/upload)

* [ASP.NET Core Upload Product Page](https://www.telerik.com/aspnet-core-ui/upload)

* [Telerik UI for ASP.NET Core Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-core-ui/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET Core Forums](https://www.telerik.com/forums/aspnet-core-ui)

## See Also

* [Client-Side API Reference of the Upload for ASP.NET Core](https://docs.telerik.com/kendo-ui/api/ui/upload)

* [Server-Side API Reference of the Upload for ASP.NET Core](https://docs.telerik.com/aspnet-core/api/upload)

* [Server-Side TagHelper API Reference of the Upload for ASP.NET Core](https://docs.telerik.com/aspnet-core/api/taghelpers/upload)

* [Telerik UI for ASP.NET Core Breaking Changes](https://www.telerik.com/aspnet-core-ui/documentation/backwards-compatibility/2023-backwards-compatibility)

* [Telerik UI for ASP.NET Core Knowledge Base](https://docs.telerik.com/aspnet-core/knowledge-base)
