Click here to Skip to main content
16,017,954 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have functions to view/remove data:

[HttpGet]
   public IActionResult Index()
   {
       ViewData["table1"] = _repository.GetAll("table1").ToList();
       ViewData["table2"] = _repository.GetAll("table2").ToList();
       return View("Index");
   }

   [HttpPost]
   public IActionResult Remove(string fromTable, List<Items> items)
   {
       try
       {
           var itemsToDelete = items.Where(x => x.Checked).ToList();
           _repository.Remove(itemsToDelete, fromTable);
       }
       return RedirectToAction("Index");
   }


@{
    const string changeQueueTable = "table1";
    const string changeQueueErrorsTable = "table2";
    var table1 = (List<Items>)ViewData["table1"];
    var table2 = (List<Items>)ViewData["table2"];
    var error = (string)ViewData["error"];
}
@if (error != null)
{
    <div class="alert alert-danger mt-3" role="alert">@error</div>
}
<div class="row" style="margin-top: 10px;">
    <div class="col-md-6" style="border-right: 1px solid #dee2e6">
        @if (changeQueue != null)
        {
            var id = 0;
            <h3>Change queue table</h3>
            <form asp-controller="ErrorConsumer" asp-action="" method="post">
                <table class="table table-striped">
                <thead>
                <tr>
                    <th>#</th>
                    <th></th>
                    <th>Object Id</th>
                    <th>Object type</th>
                </tr>
                </thead>
                <tbody>
                @if (table1.Count > 0)
                {
                    @for (var i = 0; i < table1.Count; i++)
                    {
                        <input type="hidden" name="@("items[" + i + "].ObjectId")" value="@table1[i].ObjectId"/>
                        <input type="hidden" name="@("items[" + i + "].ObjectType")" value="@table1[i].ObjectType"/>
                        <tr>
                            <td>@(++id)</td>
                            <td>
                                <input name="@("items[" + i + "].Checked")" type="checkbox" value="true" @(table1[i].Checked ? "checked" : " ")/>
                            </td>
                            <td>@table1[i].ObjectId</td>
                            <td>@table1[i].ObjectType</td>
                        </tr>
                    }
                }
                else
                {
                    <tr>
                        <td colspan="8" style="text-align: center;">No items found</td>
                    </tr>
                }
                </tbody>
            </table>
            <div class="row justify-content-end" style="margin-top: 20px;">
                <div class="col-md-2">
                    <input type="hidden" name="fromTable" value="@changeQueueTable"/>
                    <input type="hidden" name="toTable" value="@changeQueueErrorsTable"/>
                    <div style="float: right">
                        <button style="width: 84px; margin-right: -30px; @(table1.Count == 0 ? "display:none" : "display:block")" class="btn btn-primary" asp-action="Move" title="Move" type="submit">Move</button>
                    </div>
                </div>
                <div class="col-md-2">
                    <div style="margin-left: -10px; float: right">
                        <button class="btn btn-secondary" style="@(table1.Count == 0 ? "display:none" : "display:block")" asp-action="Remove" title="Remove " type="submit">Remove</button>
                    </div>
                </div>
            </div>
            </form>
        }

    </div>
</div>


What I have tried:

This worked correctly, but now I noticed that when the list is bigger (+500 items in a list) my remove method gets null values (here:
IActionResult Remove(string fromTable, List<ChangeQueueItem> items)
). What could be wrong here? Why it works correctly with 10 items in a list, but does not pass values when list is bigger?
Posted
Updated 14-Apr-22 2:11am

1 solution

There's a limit on the size of the request. See c# - Increase upload file size in Asp.Net core - Stack Overflow[^]. Be sure to read ALL of the answers before tinkering with your code. There's multiple possible solutions depending on your exact circumstances.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900