title: How to make a POST request without overposting the entire ViewModel, but preserving the current ViewModel data in the View in case of failrue
body: <p>I have an API backend project, Identity Provider made with Identity Server 4 and MVC client project.
  Let's assume for simplicity that I have <code>OrganizationDetailsViewModel</code> looking like stated below with few properties and a collection of members. <code>SearchMetadata </code> is an object containing search, filtering and pagination data.</p>
  <pre><code>    public class OrganizationDetailsViewModel
      {
          public Guid Id { get; set; }
          public string Name { get; set; }
          public string Description { get; set; }
          public IEnumerable&lt;MemberListDto&gt; Members { get; set; }
          public MembersResourceParameters SearchMetadata { get; set; }
      }
  </code></pre>
  <p>Members are displayed in a table with pagination, where there are few buttons with diffrent actions bound to it (e.g. edit, delete, promote) for each member. E.g. edit leads to separate edit view with a form to update properties like <code>Name</code> and <code>Description</code>. The flow looks like this:</p>
  <pre><code>        [HttpPost]
          [ValidateAntiForgeryToken]
          public async Task&lt;IActionResult&gt; Edit(EditOrganizationViewModel model)
          {
              if (!ModelState.IsValid)
                  return View(model);
  
              var result = await _organizationService.Update(model.Id,
                  _mapper.Map&lt;EditOrganizationRequest&gt;(model));
  
              if (result.IsFailure)
                  return CreateErrorActionResult(result.Error, model);
  
              return RedirectToAction(actionName:&quot;Details&quot;, controllerName:&quot;Organization&quot;, fragment:&quot;?organizationId=&quot; + model.Id);
          }
  </code></pre>
  <p><code>_organizationService</code> is service which handles communication with API backend, <code>CreateErrorActionResult</code> method on <code>400</code> or <code>412</code> adds errors returned by API to modelState and returns <code>View(model)</code>. For other error codes acts accordingly. The problem I have is when user clicks button promote on detail page I'm calling this function in MemberController:</p>
  <pre><code>[HttpPost]
  public async Task&lt;IActionResult&gt; Promote(Guid organizationId, Guid memberId)
  </code></pre>
  <p>and if api handling service returns and error(<code>400</code>), because some of domain business rules was invalid, similary like in <code>Edit</code> action, I would like to add errors to model state and return the same view (which is the same detail view) in order to display error message and keep current pagination (overall table) state, otherise redirect to detail view to reload updated data (no need to maintain filtering, search and pagination state of table). The problems are, that if I want to return <code>View(&quot;Details&quot;, &quot;Organization&quot;, ...)</code> in case of an error:</p>
  <ol>
  <li>I would need to post all the data from <code>OrganizationDetailsViewModel</code> as hidden input in some kind of form instead of having just a button. Then return this data to the view with updated modelState</li>
  </ol>
  <p>or</p>
  <ol start="2">
  <li>Post only searchMetadata and if api would return and <code>400' requery API for data in </code>OrganizationDetailsViewModel`, map it to the view model and return.</li>
  </ol>
  <p>but even if I do so I'm still in the Promote method url...</p>
  <p>Controller Redirect methods allow on passing only url and routeValues and it would be really weird to pass it in the query. Futhermore it would also require requering the API for data that I already had. Other options I have thought about is doing a call with jquery-ajax, but I'm not sure about it, because MVC is being authorized with <code>code</code> flow from Identity Server 4, which is meant for server to server communication. For a call performed with ajax I would most likely need to implement another <code>implicit</code> flow. The last option I came up with is to post all <code>OrganizationDetailsViewModel</code> data to <code>Promote</code> controller method, and in case of and error add it to <code>tempData</code> dictionary then redirect to Details view and read required data from there. But from what I've read it's highly inadvisable, because it includes sessions management. What I'm thinking about now is to call with ajax a method in member controller (local URL) instead of API, but I'm almost certain that it would not keep the user identity and following call to the API would result in being unauthorized, because token would not be added in the <code>DelegatingHandler</code>.</p>