title: Using javascript to call controller method in MVC
body: <p>Im trying to make a table row work as a link to another view in my mvc website. Instead of using the standard "Details" link provided by the auto generated table list, I would like to use the table row as a link to the "Details" view instead. So somehow I need to make the row work as a link. Each rom has a unique id that I need to pass on to the controller method. I have tried different solutions but noting happens when I press on the table row...</p>
  
  <p>So far this is what I have:
      
      
      </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(document).ready(function(){
      $('#customers tr').click(function () {
          var id = $(this).attr('id');
          $.ajax({
              url: "Customer/Details" + id,
              succes: function () { }
          });
      })
  })
  &lt;/script&gt;
  </code></pre>
  
  <p>My controller method:</p>
  
  <pre><code>public ActionResult Details(int id)
  {
      Customer model = new Customer();
      model = this.dbEntities.Customers.Where(c =&gt; c.Customer_ID == id).Single();
      return View(model);
  }
  </code></pre>
  
  <p>Global.asax:</p>
  
  <pre><code>public static void RegisterGlobalFilters(GlobalFilterCollection filters)
  {
      filters.Add(new HandleErrorAttribute());
  }
  
  public static void RegisterRoutes(RouteCollection routes)
  {
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
      routes.MapRoute(
          "Default", // Route name
          "{controller}/{action}/{id}", // URL with parameters
          new { controller = "Home", action = "Index", id = UrlParameter.Optional }     
      );
  
      routes.MapRoute(
          "CustomerDetails",
          "Customer/Details/{id}",
          new { controller = "Customer", action = "Details", id = "" }
      );
  }
  
  protected void Application_Start()
  {
      AreaRegistration.RegisterAllAreas();
  
      // Use LocalDB for Entity Framework by default
      Database.DefaultConnectionFactory = new SqlConnectionFactory(@"Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True");
  
      RegisterGlobalFilters(GlobalFilters.Filters);
      RegisterRoutes(RouteTable.Routes);
  }
  </code></pre>