title: MVC Restful routing and returning Views
body: <p>My question is very similar to this one <a href="https://stackoverflow.com/questions/6723531/mvc-rest-and-returning-views">MVC Rest and returning views</a> but the answer isn't working for me. I have implemented Restful Routing in my MVC application using (<a href="http://restfulrouting.com/" rel="nofollow noreferrer">http://restfulrouting.com/</a>). </p>
  
  <p>When I want to add a new record the url is: </p>
  
  <pre><code>localhost/operations/1/exhibits/new
  </code></pre>
  
  <p>This calls the New action which returns New.cshtml as the view which contains a form. When the user submits the form and the Create action is called successfully on the Exhibits controller. </p>
  
  <p>If the model state has errors I would like to return back to the New view with the date entered by the use still in place and show an error message (not implemented yet).</p>
  
  <p>At present</p>
  
  <pre><code>return View("New", model)
  </code></pre>
  
  <p>sends back the data and renders the "New" view but the url changes to:</p>
  
  <pre><code>/localhost/operations/1/exhibits
  </code></pre>
  
  <p>I have checked the route values and the action being returned still is "create". I have navigation links that are driven by the action and controller values and the incorrect url means these don't get rendered properly.</p>
  
  <p><strong><em>Controller</em></strong></p>
  
  <pre><code>public class ExhibitController : Controller
  {
      public ActionResult Index()
      {
          CreateExhibitViewModel model = new CreateExhibitViewModel();
          return View(model);
      }
  
      public ActionResult New()
      {
          return View();
      }
  
      [HttpPost]
      public ActionResult Create(MyModel model)
      {
          if(!ModelState.IsValid)
          {
              return View("New", model")   
          }
  
          // Process my model
          return RedirectToAction("Index");
      }
  }
  </code></pre>
  
  <p><strong><em>View</em></strong></p>
  
  <pre><code>@model RocketBook.Web.ViewModels.Exhibit.CreateExhibitViewModel
  
  @{
      Html.HttpMethodOverride(HttpVerbs.Put);
      ViewBag.Title = "Operation " + ViewBag.OperationName;
  }
  
  &lt;div class="panel panel-default"&gt;
      &lt;div class="panel-heading"&gt;
          &lt;h4&gt;New Exhibit&lt;/h4&gt;
      &lt;/div&gt;
      &lt;div class="panel-body"&gt;
          &lt;div class="col-lg-6 form-horizontal"&gt;
              @using (var form = Html.Bootstrap().Begin(new Form("create", "exhibit").Id("newexhibit").Type(FormType.Horizontal).FormMethod(FormMethod.Post).WidthLg(4)))
              {
                  @Html.AntiForgeryToken()                  
                  &lt;fieldset&gt;
                      &lt;legend&gt;Details&lt;/legend&gt;
                      @Html.HiddenFor(m =&gt; m.OperationID)
                      @Html.HiddenFor(m =&gt; m.JobID)
                      @form.FormGroup().TextBoxFor(m =&gt; m.Barcode)
                      @form.FormGroup().TextBoxFor(m =&gt; m.ExhibitRef)
                      @form.FormGroup().TextBoxFor(m =&gt; m.ExhibitDescription)
                      @form.FormGroup().DropDownListFor(m =&gt; m.ClassificationGroupID, Model.ClassificationGroups).OptionLabel("")
                      @form.FormGroup().DropDownListFor(m =&gt; m.ClassificationID, Model.Classifications).OptionLabel("")
                      @form.FormGroup().DropDownListFor(m =&gt; m.ExhibitPriority, Model.EntityPriorities).OptionLabel("")
                  &lt;/fieldset&gt; 
                  &lt;hr /&gt;
                  @(form.FormGroup().CustomControls(
                  Html.Bootstrap().SubmitButton().Style(ButtonStyle.Primary).Text("Add Exhibit")))
  
              }
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>