title: Using MVC. I'm trying to click a button client side to retrieve a database, so that may also appear on the browser
body: <p>I am creating a sign in - signout app using MVC C# Visual Studio and I need some assistance.</p>
  
  <p>Whenever I try to click the button to get an <code>onclick</code> event, it is suppose to call the <code>GetList</code> method and retrieve all of the data in the database where Signout is equal to null in the Visitor column.</p>
  
  <p>It is not hitting the <code>GetList</code> method. What do I need to do to move forward?</p>
  
  <p>This is my code:</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>using NameSpaceName.Models;
  using System;
  using System.Collections.Generic;
  using System.ComponentModel.DataAnnotations;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using System.Configuration;
  using System.Net;
  using System.Data.SqlClient;
  using ClassLibrary1;
  using System.Data;
  
  namespace NameSpaceName.Controllers {
      public class VisitorController : Controller {
          // GET: Visitor
          [HttpGet]
          public ActionResult Index(int id=0) {
              Visitor visitor = new Visitor();
              Entities db = new Entities();
              var employee = db.Employees.ToList();
              return View(visitor);
          }
  
          [HttpGet]
          public ActionResult GetList(Visitor visitor) {
              List&lt;String&gt; Visitor = new List&lt;String&gt;();
              using (Entities db = new Entities()) {
                  if (visitor.SignOut == null) {
                  //
                  }
              }
              return View(visitor);
          }
  
          [HttpPost]
          public ActionResult SubmitInfo(FormModel model) {
              return new JsonResult() {
                  Data = model,
                  MaxJsonLength = int.MaxValue,
              };
          }
      }
  }
  </code></pre>
  
  <p><strong>RouteConfig.cs</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using System.Web.Routing;
  
  namespace NameSpaceName.Web {
      public class RouteConfig {
          public static void RegisterRoutes(RouteCollection routes) {
              routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
              routes.MapRoute(
                  "Submit Info", // Route name
                  "visitor/submit-info/", // URL with parameters
                  new { controller = "Visitor", action = "SubmitInfo" } 
              );
  
              routes.MapRoute(
                  "Get Info", // Route name
                  "visitor/get-info/", // URL with parameters
                  new { controller = "Visitor", action = "GetInfo" }
              );
  
              routes.MapRoute(
                  name: "Default",
                  url: "{id}",
                  defaults: new { controller = "Visitor", action = "Index", id = UrlParameter.Optional }
              );
          }
      }
  }
  </code></pre>
  
  <p><strong>Partial View _SignInOrSignOut</strong></p>
  
  <pre><code>@using NameSpaceName;
  @using ClassLibrary1;
  
  @model Visitor
  @{
      ViewBag.Title = "GetInfo";
  }
  @{
      AjaxOptions options = new AjaxOptions {
          HttpMethod = "GET",
          OnSuccess = "GetList",
          OnFailure = "NoList",
          Url = "/visitor/get-info/"
      };
  }
  &lt;ul class="col-xs-12"&gt;
      &lt;li class="col-xs-6"&gt;
          &lt;input type="button" class="btn-cls SignIn" value="Sign In" name="Sign In" /&gt;
      &lt;/li&gt;
      &lt;li class="col-xs-6"&gt;
          &lt;input type="button" value="Sign Out" class="btn-cls SignOut" name="Sign Out" onclick="@Url.Action("GetInfo", "Visitor")" /&gt;
      &lt;/li&gt;
  &lt;/ul&gt;
  
  //jQuery code
  $(document).ready(function () {
      window.formSuccess = function (resp) {
          setTimeout(function () {
              $(".signInForm").hide();
              $(".signInBtn").show();
          }, 3000);
      };
  
      window.formFails = function (resp) {
          debugger;
      };
      window.GetList = function (resp) { alert("Yay"); };
      window.NoList = function (resp) { alert("No"); };
  }).on('click', '.btn-cls', function() {
      var $this = $(this);
      if ($this.is('.SignIn')) {
          $(".signInBtn").hide();
          $(".signInForm").show();
      } else {
          console.log('SignOut');
      }
  });
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>&lt;div class="col-centered signInBtn col-xs-12"&gt;
      @Html.Partial("_SignInOrSignOut")
  &lt;/div&gt;
  &lt;div class="col-centered signInForm col-xs-12"&gt;
      @using (Ajax.BeginForm(null, null, options, new { @class = "visitor-form" })) {
      &lt;div class="input"&gt;
          @Html.TextBoxFor(model =&gt; model.FirstName, new {
          @class = "firstName required",
          @id = "firstName",
          @placeHolder = "First Name",
          @name = "FirstName",
          @tabIndex = 1
       })
       &lt;/div&gt;
       &lt;div class="input"&gt;
           @Html.TextBoxFor(model =&gt; model.LastName, new {
           @class = "lastName required",
           @id = "lastName",
           @name = "LastName",
           @placeHolder = "Last Name",
           @tabIndex = 2
       })
       &lt;/div&gt;
       &lt;div class="input"&gt;
           @Html.TextBoxFor(model =&gt; model.Company, new {
           @class = "company",
           @id = "company",
           @name = "Company",
           @placeHolder = "Company",
           @tabIndex = 3
       })
       &lt;/div&gt;
       &lt;div class="input"&gt;
           @Html.TextBoxFor(model =&gt; model.EmailAddress, new {
           @class = "emailAddress",
           @id = "emailAddress",
           @name = "EmailAddress",
           @placeHolder = "Email Address",
           @tabIndex = 4
       })
       &lt;/div&gt;
       &lt;div class="input"&gt;
           @Html.TextBoxFor(model =&gt; model.ReasonForVisit, new {
           @class = "reasonForVisit required",
           @id = "reasonForVisit",
           @name = "ReasonForVisit",
           @placeHolder = "Reason For Visit",
           @tabIndex = 5
       })
       &lt;/div&gt;
       &lt;div class="input"&gt;
           @Html.DropDownListFor(model =&gt; model.EmployeeId, Employee.EmployeeDropDown, new { 
                  @class="employeeList required",
              })
       &lt;/div&gt;
       @Html.HiddenFor(model =&gt; model.SignIn)
       @Html.HiddenFor(model =&gt; model.SignOut)
       @Html.HiddenFor(model =&gt; model.IsEmailed)
  
       &lt;input type="submit" value="Submit" /&gt;
  &lt;/div&gt;
  </code></pre>