title: RedirectToAction ASP .NET MVC
body: <p>I currently read Freeman's book ASP .NET MVC 4 and do a web application. So, there is a controller named "Cart" with method "AddToCart" and a View. In the view we have such code:</p>
  
  <pre><code>@model SportsStore.Domain.Entities.Product
  
  &lt;div class="item"&gt;
      &lt;h3&gt;@Model.Name&lt;/h3&gt;
      @Model.Description
      @using (Html.BeginForm("AddToCart", "Cart"))
      {
          @Html.HiddenFor(x =&gt; x.ProductID)
          @Html.Hidden("returnUrl", Request.Url.PathAndQuery)
          &lt;input type="submit" value="+ Add to cart" /&gt;
      }
  
      &lt;h4&gt;@Model.Price.ToString("c")&lt;/h4&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and the method's of the controller code:</p>
  
  <pre><code>public RedirectToRouteResult AddToCart(Cart cart, int productId, string returnUrl)
  {
     Product product = repository.Products
        .FirstOrDefault(p =&gt; p.ProductID == productId);
     if (product != null)
     {
        cart.AddItem(product, 1);
     }
     return RedirectToAction("Index", new { returnUrl });
  }
  </code></pre>
  
  <p>The code compiles very good, but I have here some questions.</p>
  
  <p>1) If you put a breakpoint on the line: </p>
  
  <pre><code>return RedirectToAction("Index", new { returnUrl });
  </code></pre>
  
  <p>you'll see that returnUrl has value "<strong>/</strong>". How? Where did he get it? </p>
  
  <p>2) What are these lines of code doing, because there is no information in the book about it.</p>
  
  <pre><code>@Html.HiddenFor(x =&gt; x.ProductID)
  @Html.Hidden("returnUrl", Request.Url.PathAndQuery)
  </code></pre>