remember the dotnet core below
public IActionResult OnPostDelete()
{
    // Clear the tempDataList to ensure it only holds the current session data
    tempDataList.Clear();

    string contentRootPath = _hostingEnvironment.WebRootPath;
    bool isFileDeleted = false;

    // Step 1: Retrieve DataList JSON from the request
    string dataListJson = Request.Form["DataList"];
    if (string.IsNullOrEmpty(dataListJson))
    {
        _logger.LogWarning("DataList is empty or missing.");
        return new JsonResult(new { success = false, message = "DataList is empty or missing." });
    }

    _logger.LogInformation($"Received DataList JSON: {dataListJson}");

    // Step 2: Deserialize the DataList JSON
    PostDataFile obj;
    try
    {
        obj = JsonConvert.DeserializeObject<PostDataFile>(dataListJson);
        _logger.LogInformation("DataList deserialized successfully.");
    }
    catch (JsonException ex)
    {
        _logger.LogError($"Deserialization failed: {ex.Message}");
        return new JsonResult(new { success = false, message = "Failed to deserialize DataList.", error = ex.Message });
    }

    if (obj?.list != null && obj.list.Count > 0)
    {
        // Create a HashSet of the incoming files for faster lookup
        var incomingFiles = new HashSet<string>(obj.list.Select(d => d.File));

        // Step 3: Remove items from dataList that are not in the incoming data, and delete associated files
        var itemsToRetain = new List<DataType>();

        foreach (var item in dataList)
        {
            if (incomingFiles.Contains(item.File))
            {
                itemsToRetain.Add(item);  // Retain items present in incoming data
            }
            else
            {
                // Delete the associated file if it exists
                string fileToDelete = Path.Combine(contentRootPath, @"Files\TempSamplesAnalyze\", item.File);
                if (System.IO.File.Exists(fileToDelete))
                {
                    try
                    {
                        System.IO.File.Delete(fileToDelete);
                        isFileDeleted = true;
                        _logger.LogInformation($"File {item.File} deleted successfully.");
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"Error deleting file {item.File}: {ex.Message}");
                    }
                }
            }
        }

        // Update dataList to retain only the intersected items
        dataList = itemsToRetain;
        _logger.LogInformation("DataList updated successfully to retain only incoming items.");
    }
    else
    {
        _logger.LogWarning("Deserialized DataList is null or empty.");
        return new JsonResult(new { success = false, message = "No valid items found in DataList." });
    }

    // Synchronize tempDataList with the updated dataList
    tempDataList = dataList;

    // Step 4: Return the Final DataList as JSON with file deletion status
    string finalJsonString = JsonConvert.SerializeObject(dataList.ToList());
    _logger.LogInformation($"Final DataList JSON: {finalJsonString}");

    return new JsonResult(new { success = true, dataList = finalJsonString, fileDeleted = isFileDeleted });
}