title: Cannot link back to MVC view via javascript
body: <p>I have an <em>Index</em> View and when I click the <em>Edit</em> button, I post to the <em>Edit</em> View (via the Controller) and display a bootstrap modal popup. </p>
  
  <p>By posting to the <em>Edit</em> View, the Controller/View automatically handle getting and displaying the correct data on the modal popup. </p>
  
  <p>Once I'm on my <em>Edit</em> View with the dialog box appearing and I click on the <em>Close</em> button, I simply want to <strong>link back</strong> to the <em>Index</em> page again; but instead, am getting an error with the path of the url. The new path I want to link to is being "<em>tacked on</em>" to the original path instead of <strong>replacing</strong> it.</p>
  
  <p>I'm using the <em>Url.Action</em> method inside the click event of the <em>Close</em> button (of which I verified it's hitting) and have verified the location.href url is exactly what is in the url variable as you see in the code.</p>
  
  <p>What do I need to do to correctly link back to the <em>Index</em> url?</p>
  
  <h2>Index View</h2>
  
  <pre><code>&lt;a href="@Url.Action("Edit", "Category", new { area="Categories", id = item.CategoryID })"&gt;&lt;span class="glyphicon glyphicon-edit" aria-hidden="true"&gt;&lt;/span&gt;Edit&lt;/a&gt;
  </code></pre>
  
  <h2>Edit Controller</h2>
  
  <pre><code>// GET: Categories/Edit/5
  public async Task&lt;ActionResult&gt; Edit(short id)
  {
      if (id == 0)
      {
          return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
      }
  
      Category category = await db.GetCategoryIDAsync(id);
  
      if (category == null)
      {
          return HttpNotFound();
      }
  
      return View(category);
  }
  </code></pre>
  
  <h2>Edit View</h2>
  
  <pre><code>@model YeagerTechDB.Models.Category
  
  @{
      ViewBag.Title = "Edit";
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  &lt;div class="modal" id="categoryEditModal" tabindex="-1" role="dialog" aria-labelledby="categoryModal-label" aria-hidden="true"&gt;
      &lt;div class="modal-dialog"&gt;
          &lt;div class="modal-content"&gt;
              &lt;div class="modal-header"&gt;
                  &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
                  &lt;h4 class="modal-title" id="categoryModal-label"&gt;Category Description&lt;/h4&gt;
              &lt;/div&gt;
              &lt;div class="modal-body"&gt;
                  &lt;div class="form-group"&gt;
                      @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                      &lt;div class="form-group"&gt;
                          @Html.LabelFor(model =&gt; model.CategoryDescription, new { @class = "control-label required col-offset-1 col-lg-3 col-md-3 col-sm-3 col-xs-3" })
                          &lt;div class="col-lg-8 col-md-8 col-sm-8 col-xs-8"&gt;
                              @Html.EditorFor(model =&gt; model.CategoryDescription, new { @class = "form-control" } )
                              @Html.ValidationMessageFor(model =&gt; model.CategoryDescription, "", new { @class = "text-danger" })
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="modal-footer"&gt;
                  &lt;button type="submit" class="btn btn-default" id="btnCloseCategory"&gt;Close&lt;/button&gt;
                  &lt;button type="submit" class="btn btn-primary" id="btnSaveCategory"&gt;Save&lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div&gt;
      @Html.Hidden("categoryEditUrl", Url.Action("Edit", "Category", new { area = "Categories" }))
      @Html.Hidden("catID", Model.CategoryID)
  &lt;/div&gt;
  
  @section Scripts {
      &lt;script&gt;
          $(document).ready(function ()
          {
              if (typeof contentEditCategory == "function")
                  contentEditCategory()
          });
      &lt;/script&gt;
  }
  </code></pre>
  
  <h2>JS for Edit View</h2>
  
  <pre><code>$('#btnCloseCategory').click(function (e)
  {
      var url = '@Url.Action("Index", "Category", new { area = "Categories" })';
      location.href = url;
  
      return false;
  });
  </code></pre>
  
  <h2>Image of modal popup</h2>
  
  <p><img src="https://i.stack.imgur.com/pFcST.png" alt="enter image description here"></p>
  
  <h2>Image of error</h2>
  
  <p><img src="https://i.stack.imgur.com/OYZyr.png" alt="enter image description here"></p>