title: Jquery or Javascript Redirect to Controller/Action
body: <p>I have the following code which works on the first time around:</p>
  
  <pre><code>$("#CompDD").change(function () {
                  //var parts = (window.location.pathname.split("/"));
                  var ctrlName = '@ViewContext.RouteData.Values["Controller"].ToString()';
                  var actnName = '@ViewContext.RouteData.Values["Action"].ToString()';
                  var url = (ctrlName + "/" + actnName + "/?SearchString=" + $('#CompDD option:selected').text() + "&amp;atton=" + $('#AttDD option:selected').val());
                  //delete ctrlName;
                 // delete actnName;
                  //window.location = ($(location).attr('href') + "/?SearchString=" + $('#CompDD option:selected').text() + "&amp;atton=" + $('#AttDD option:selected').val());
                  //window.location = (ctrlName + "/" + actnName + "/?SearchString=" + $('#CompDD option:selected').text() + "&amp;atton=" + $('#AttDD option:selected').val());
                  //$(location).attr('href', url);
                  window.location.href = url;
                  //alert(ctrlName + "\n" + actnName);
              });
  </code></pre>
  
  <p>However on subsequent changes of the drop down in question (#CompDD) it will add another controller/action to the end of the link, ex. it adds another "Patrons/Index" to the end of the existing "Patrons/Index", thenit adds the searchsrting variables etc.</p>
  
  <p>Please excuse the comments and stuff on my code.  How do i get Jquery (or javascript) to redirect without appending the controller name and action names over and over, or whats the best way to do this?</p>
  
  <p>EDIT: Such an easy fix!  I had to add the root slash to the URL string, example this worked:</p>
  
  <pre><code>var url = ("/" + ctrlName + "/" + actnName + "/?SearchString=" + $('#CompDD option:selected').text() + "&amp;atton=" + $('#AttDD option:selected').val());
  </code></pre>
  
  <p>Notice the forward slash at the start of the string I construct....Yikes!</p>