title: ASP.NET MVC: Redirecting from one view to another
body: <p>Hi I am using the following code to redirect from a kendo grid to another page (View): </p>
  
  <pre><code>@(Html.Kendo().Grid&lt;WM.ViewModels.StockReceiptsGridViewModel&gt;()
      .Name("Grid")
      .ToolBar(toolbar =&gt; toolbar.Template("&lt;a class='k-button k-button-icontext' onclick='addMaterialPopup()' href='#'&gt;&lt;/span&gt;Create Stock Receipt&lt;/a&gt;"))
      .Columns(columns =&gt;
      {
          columns.Bound(p =&gt; p.StockReceiptID);
          columns.Bound(p =&gt; p.SupplierName);
          columns.Bound(p =&gt; p.Product);
          columns.Bound(p =&gt; p.Dimensions);
          columns.Bound(p =&gt; p.Quantity);
          columns.Bound(p =&gt; p.QuantityReserved);
          columns.Bound(p =&gt; p.PurchaseNumber);
          columns.Bound(p =&gt; p.Cost);
          columns.Bound(p =&gt; p.PhotosLink).Title("").ClientTemplate("&lt;a href='/Photos/index?StockReceiptID=#=StockReceiptID#'&gt;#=GetText()#&lt;/a&gt;");
          columns.Command(command =&gt; command.Custom("Edit").Click("editreceipt"));
  
      })
      .DataSource(dataSource =&gt; dataSource
          .Ajax()
          .Batch(false)
          .Model(model =&gt; model.Id(p =&gt; p.StockReceiptID))
                      .Read(read =&gt; read.Action("Read", "StockReceiptsGrid").Data("ExtraData"))
    )
  )
  </code></pre>
  
  <p><strong>Javascript:</strong></p>
  
  <pre><code>function editreceipt(e) {
      e.preventDefault();
      var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
      var stockReceiptId = dataItem.StockReceiptID;
  
      window.location.href = "@Url.Action("Update","StockReceipt")"+"/"+stockReceiptId; // Problem code...
  
      }
  </code></pre>
  
  <p>The receiving method on the StockReceipt Controller is: </p>
  
  <pre><code>public ActionResult Update(int stockReceiptId)
  {
     var stockReceipt = _stockReceiptRepository.GetAllStockReceipts().ToList().Where(r =&gt; r.StockReceiptID == stockReceiptId);
  
      var model = new StockReceiptViewModel();
  
  
      model.Notes = stockReceipt.First().Notes;
  
  
  
      return View("Index", model);
  }
  </code></pre>
  
  <p>And here is my route configuration: </p>
  
  <pre><code>public static void RegisterRoutes(RouteCollection routes)
  {
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
      routes.MapRoute(
          name: "Default",
          url: "{controller}/{action}/{id}",
          defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
      );
  }
  </code></pre>
  
  <p><strong>The Problem:</strong></p>
  
  <p>.. is that the above Javascript code is not redirecting, it is taking me to this URL: http:<code>//localhost:50439/StockReceipt/6</code></p>
  
  <p>And reporting the 'Yellow Screen of Death' with this error: </p>
  
  <p>The parameters dictionary contains a null entry for parameter 'stockReceiptId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Update(Int32)' in 'WorcesterMarble.Controllers.StockReceiptController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
  Parameter name: parameters</p>
  
  <p>Where 6 is the ID.</p>
  
  <p>If I remove the id element to become like this: </p>
  
  <pre><code>window.location.href = "@Url.Action("Update","StockReceipt")"
  </code></pre>
  
  <p>It works, but I need the ID because I want to load the selected 'ViewModel' in the destination view. </p>
  
  <p>I wonder what am I doing wrong?!</p>
  
  <p>I have tried using this, but to no avail.: </p>
  
  <pre><code>window.location.href = @Url.RouteUrl("Default", new { @Controller = "StockReceipt", @Action = "Update"}) + '//' + stockReceiptId;
  </code></pre>