title: ASP.NET Core MVC submit form in partial view / ViewComponent
body: <p>I have a menu and a content area which displays content based on the selected item in the menu. Since the user is allowed to change the structure of the main menu, I decided that everything will be on page /home/index and will have a guid assigned to the content which needs to be shown. I started with the idea to introduce partial views, but realized that ASP.NET Core doesn't have RenderAction anymore and was replaced by ViewComponents.
  So I used ViewComponents and everything works fine, except that I've stumbled on a situation where I need to have a component as a submit form.</p>
  
  <p>In an example: One menu item is the menu is a component that shows a list of users. Another menu item is a component that creates a new user. On create user component I'll have a form that needs to be filled and on successful submit, I want to redirect the user to the component that shows a list of users. In the case of unsuccessful submit, error, wrong input I would of course not want to redirect the user to the list of users.</p>
  
  <p>Since ViewComponents' job is to display view, how should I approach this issue? I'm looking for pointers in the right direction.
  I have little experience in this field so any help would be appreciated.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>In <em>Index.cshtml</em>:</p>
  
  <pre><code>&lt;tbody&gt;
      @foreach (string item in Model.Components)
      {
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;div class="col-md-3"&gt;
                      @await Component.InvokeAsync(@item)
                  &lt;/div&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      }
  &lt;/tbody&gt;
  </code></pre>
  
  <p>This is inside the content area. <em>Components</em> are string names of components I'd like to show in the content area (currently listed one after the other).</p>
  
  <p>My ViewComponent which will get called when I click on the menu item to display the form:</p>
  
  <pre><code>public class TestFormViewComponent : ViewComponent
  {
      public async Task&lt;IViewComponentResult&gt; InvokeAsync()
      {
          return View("_TestForm", new TestModelPost());
      }
  }
  </code></pre>
  
  <p>My <em>_TestForm.cshtml</em> component:</p>
  
  <pre><code>@model TestModelPost
  &lt;form asp-controller="Home" asp-action="TestPost" method="post"&gt;
      &lt;label asp-for="Name"&gt;&lt;/label&gt;
      &lt;input asp-for="Name" /&gt;&lt;br /&gt;
      &lt;label asp-for="Surname"&gt;&lt;/label&gt;
      &lt;input asp-for="Surname" /&gt;&lt;br /&gt;
      &lt;button type="submit"&gt;Go&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And the action TestPost called:</p>
  
  <pre><code>[HttpPost]
  public IActionResult TestPost(TestModelPost model)
  {
      // Save model data, etc
      // !ModelState.IsValid -&gt; go back to form
  
      // Success -&gt; go to specific id
      return RedirectToAction("Index", new { id = 1 });
  }
  </code></pre>
  
  <p>How should I approach this? Or rather, am I even on the right track? I'm not sure how I would go "back" to that view I created in my _TestForm component in case the input was incorrect.</p>