title: Return ViewData from view to controller razor pages
body: <p>I have view is C#:</p>
  <pre><code>@{
      var itemList = (List&lt;Item&gt;)ViewData[&quot;itemsList&quot;];
  }
  &lt;div class=&quot;row&quot; style=&quot;margin-top: 10px;&quot;&gt;
      &lt;div class=&quot;col-md-6&quot;&gt;
          @if (itemList != null)
          {
              var id = 0;
              &lt;table class=&quot;table table-striped&quot;&gt;
                  &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th&gt;#&lt;/th&gt;
                      &lt;th&gt;&lt;/th&gt;
                      &lt;th&gt;Id&lt;/th&gt;
                      &lt;th&gt;Type&lt;/th&gt;
                  &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;
                      @foreach (var result in itemsList)
                      {
                          &lt;tr&gt;
                              &lt;td&gt;@(++id)&lt;/td&gt;
                              &lt;td&gt;&lt;input type=&quot;checkbox&quot; value=&quot;true&quot; @(result.Checked ? &quot;checked&quot; : &quot;&quot;)&gt;&lt;/td&gt;
                              &lt;td&gt;@result.Id&lt;/td&gt;
                              &lt;td&gt;@result.Type&lt;/td&gt;
                          &lt;/tr&gt;
                      }
                  &lt;/tbody&gt;
              &lt;/table&gt;
          }
          &lt;div class=&quot;row justify-content-end&quot; style=&quot;margin-top: 20px;&quot;&gt;
              &lt;div class=&quot;col-md-2&quot;&gt;
                  &lt;form asp-controller=&quot;Control&quot; asp-action=&quot;Remove&quot; method=&quot;post&quot;&gt;
                      &lt;input type=&quot;hidden&quot; name=&quot;tableName&quot; value=&quot;table&quot;/&gt;
                      &lt;input type=&quot;hidden&quot; name=&quot;items&quot; value=&quot;@itemList&quot;/&gt;
                      &lt;div style=&quot;margin-left: -10px;&quot; class=&quot;col-md-2&quot;&gt;
                          &lt;button class=&quot;btn btn-danger&quot; title=&quot;Remove&quot; type=&quot;submit&quot;&gt;Remove&lt;/button&gt;
                      &lt;/div&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>I want to remove items from table, where user checks the checkbox. My idea was to update each checked item withing the list (<code>result.Checked</code> property) and then send array to Remove method:</p>
  <pre><code>[HttpPost]
  public async Task&lt;IActionResult&gt; Remove(string tableName, List&lt;ChangeQueueItem&gt; items)
  {
      try
      {
          var toDelete = items.Where(x =&gt; x.Checked == true);
  
          await _repository.RemoveFromQueue(toDelete, tableName);
      }
      catch (Exception e)
      {
          TempData[&quot;error&quot;] = e.Message;
      }
      return RedirectToAction(&quot;Index&quot;);
  }
  </code></pre>
  <p>I am trying to send that list like this:</p>
  <p><code>&lt;input type=&quot;hidden&quot; name=&quot;items&quot; value=&quot;@itemList&quot;/&gt; </code></p>
  <p>however the value is null. How should I do it?</p>
  <p>Update: data is loaded here:</p>
  <pre><code>[HttpGet]
  public async Task&lt;IActionResult&gt; Index()
  {
       var items = await _repository.GetAll();
       
      ViewData[&quot;itemsList&quot;] = items;
      ViewData[&quot;error&quot;] = TempData[&quot;error&quot;];
  
      return View(&quot;Index&quot;);
  }
  </code></pre>