title: Redirect to action with JsonResult in MVC
body: <p>I have a Room record in my database and I want to edit it using a <code>JsonResult</code> <code>Edit</code> method in <code>RoomController</code> like this:</p>
  
  <pre><code>    [HttpPost]
      [ValidateAntiForgeryToken]
      public JsonResult Edit(RoomViewModel roomViewModel)
      {
          if (roomViewModel == null) throw new ArgumentNullException(nameof(roomViewModel));
          try
          {
              var apartmentRoomViewModel = new ApartmentRoomViewModel
              {
                  Id = _entities.ApartmentRoom.Where(x =&gt; x.RoomID == roomViewModel.Id).Select(x =&gt; x.Id).Single(),
                  ApartmentID = _entities.ApartmentRoom.Where(x =&gt; x.RoomID == roomViewModel.Id).Select(x =&gt; x.ApartmentID).Single(),
                  RoomID = roomViewModel.Id
              };
              apartmentRoomViewModel.ApartmentID = roomViewModel.SelectedApartmentID;
  
              var apartmentRoom = AutoMapper.Mapper.Map&lt;ApartmentRoom&gt;(apartmentRoomViewModel);
              _entities.ApartmentRoom.AddOrUpdate(apartmentRoom);
              _entities.SaveChanges();
  
              var room = AutoMapper.Mapper.Map&lt;Room&gt;(roomViewModel);
              var status = _roomRepository.Update(room);
              _roomRepository.Save();
  
              return Json(new { status, message = "Success!", url = Url.Action("List", "Room") });
          }
          catch
          {
              return Json(new { status = false, message = "Error!" });
          }
      }
  </code></pre>
  
  <p>After the method works, edit is successful but I cannot redirect the page to /Room/List. Instead, I am encountering a page like this:</p>
  
  <p><a href="https://i.stack.imgur.com/Pq9Kn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Pq9Kn.png" alt="Wrong result"></a></p>
  
  <p><strong>My Script</strong></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(document).ready(function () {
      $("#RoomEdit").click(function (e) {
          e.preventDefault();
          var data = {
              DoorNumber: $("#DoorNumber").val(),
              FloorNumber: $("#FloorNumber").val(),
              Capacity: $("#Capacity").val(),
              SelectedApartmentID: $("#SelectedApartmentID option:selected").val()
          }
          $.ajax({
              type: "POST",
              url: '@Url.Action("Edit","Room")',
              dataType: "json",
              data: JSON.stringify(data),
              contentType: "application/json",
              success: function (result) {
                  if (result.status) {
  
                      window.location.href = result.url;
                  }
              },
              error: function () {
              }
          });
          return false;
      });
  
  });
  </code></pre>
  
  <p></p>
  
  <p><strong>Edit.cshtml</strong></p>
  
  <pre><code>&lt;div class="row"&gt;
  
  &lt;div class="col-md-10 offset-md-1"&gt;
      &lt;div class="box"&gt;
          &lt;div class="box-header"&gt;
              &lt;h2&gt;@ViewBag.Title&lt;/h2&gt;
          &lt;/div&gt;
          &lt;div class="box-divider m-a-0"&gt;&lt;/div&gt;
          &lt;div class="box-body"&gt;
              @using (Html.BeginForm("Edit", "Room", FormMethod.Post))
              {
                  @Html.AntiForgeryToken()
                  @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                  &lt;div class="form-group row"&gt;
                      @Html.LabelFor(x =&gt; x.DoorNumber, new { @class = "col-sm-2 form-control-label" })
                      &lt;div class="col-sm-10"&gt;
                          @Html.TextBoxFor(x =&gt; x.DoorNumber, new { @class = "form-control" })
                          @Html.ValidationMessageFor(x =&gt; x.DoorNumber, "", new { @class = "text-danger" })
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group row"&gt;
                      @Html.LabelFor(x =&gt; x.FloorNumber, new { @class = "col-sm-2 form-control-label" })
                      &lt;div class="col-sm-10"&gt;
                          @Html.TextBoxFor(x =&gt; x.FloorNumber, new { @class = "form-control" })
                          @Html.ValidationMessageFor(x =&gt; x.FloorNumber, "", new { @class = "text-danger" })
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group row"&gt;
                      @Html.LabelFor(x =&gt; x.Capacity, new { @class = "col-sm-2 form-control-label" })
                      &lt;div class="col-sm-10"&gt;
                          @Html.TextBoxFor(x =&gt; x.Capacity, new { @class = "form-control" })
                          @Html.ValidationMessageFor(x =&gt; x.Capacity, "", new { @class = "text-danger" })
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group row"&gt;
                      @Html.LabelFor(x =&gt; x.ApartmentName, new { @class = "col-sm-2 form-control-label" })
                      &lt;div class="col-sm-10"&gt;
                          @Html.DropDownListFor(x =&gt; x.SelectedApartmentID, Model.ApartmentList, new { @class = "form-control", id = "SelectedApartmentID" })
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group row m-t-md"&gt;
                      &lt;div class="col-sm-offset-2 col-sm-10"&gt;
                          &lt;button type="button" id="RoomEdit" class="btn green"&gt;Düzenle&lt;/button&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              }
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>I couldn't understand what is wrong with my code. Any help will be appreciated.</p>