title: ASP MVC and changing url of posted form
body: <p>I have an MVC 4 app and I am using a RESTful methodology for my URLs.  I have the following routes registered in my app (along with others that are not relevant to my question:</p>
  
  <pre><code>    //EDIT
      routes.MapRoute(alias + "_EDIT", alias + "/{id}/edit",
                      new { controller = controllerName, action = "edit" },
                      new { httpMethod = new RestfulHttpMethodConstraint(HttpVerbs.Get) });
  
      //PUT (update)
      routes.MapRoute(alias + "_PUT", alias + "/{id}",
                      new { controller = controllerName, action = "update" },
                      new { httpMethod = new RestfulHttpMethodConstraint(HttpVerbs.Put) });
  </code></pre>
  
  <p>I have the following methos in my controller mapping to these routes:</p>
  
  <pre><code>public override ActionResult Edit(int id)
  {...}
  
  public override ActionResult Update(RequestEditViewModel userModel)
  {
     if (!ModelState.IsValid)
     {
      //do some stuff to ensure lookups are populated
      ...
          return View("Edit", userModel);
     }
  }
  </code></pre>
  
  <p>In my app when I perform a request to edit a request my URL looks like:</p>
  
  <p><code>http://server/request/1/edit</code></p>
  
  <p>it correctly calls the Edit method on my controller.</p>
  
  <p>My Edit.cshtml uses the followng to ensure the Update method is called on PUT:</p>
  
  <pre><code>@using (Html.BeginForm("Update", "Request"))
  {
      @Html.HttpMethodOverride(HttpVerbs.Put);
      ...
  }
  </code></pre>
  
  <p>My form is generated as follows:</p>
  
  <pre><code>&lt;form action="/requests/71" method="post" autocomplete="off" novalidate="novalidate"&gt;
  &lt;input name="X-HTTP-Method-Override" type="hidden" value="PUT"/&gt;
  ...
  &lt;/form&gt;
  </code></pre>
  
  <p>When I click the submit button it correctly calls my Update method.</p>
  
  <p>OK...Now for the issue.  If my model is NOT valid I want to return back the Edit model.  As you can see in the above code but, the URL is the one called from the submit button:</p>
  
  <pre><code>http://server/request/1
  </code></pre>
  
  <p>not </p>
  
  <pre><code>http://server/requests/1/edit
  </code></pre>
  
  <p>I have tried an reviewed two other options but both of these redirect the request back through the Edit method again which adds additional overhead and also puts all the model values in the querystring which I do NOT want:</p>
  
  <pre><code>return RedirectToAction("Edit", userModel);
  return RedirectToRoute("requests_Edit", userModel);
  </code></pre>
  
  <p>So, <strong>is there a way to just return the View as I have in my code but, ensure the URL changes back and include the "/edit"?</strong>  </p>
  
  <p>The only alternative I have come up with is to perform an AJAX call and put the update that way the URL never changes, but I was trying to avoid that for this form.</p>