How to bind Search bar contents in View to Controller MVC
<p>I have created a search bar with two radio buttons in my Index view of my Customer model in MVC5.  I want to pass the contents of the search bar, namely which radio button has been selected and what has been entered into the search bar, to my CustomersController.  The controller, however, is not "seeing" the names in the view.  What am I doing wrong?</p>

<p>Search bar code in Index view:</p>

<pre><code>@using (Html.BeginForm("Index", "CustomersController", FormMethod.Get))
{
    &lt;b&gt;Search by:&lt;/b&gt;@Html.RadioButton("searchBy", "Company")&lt;text&gt; Company&lt;/text&gt;
    @Html.RadioButton("searchBy", "Last Name")&lt;text&gt;Last Name&lt;/text&gt;&lt;br /&gt;
    @Html.TextBox("Search");&lt;input type="submit" value="Search" /&gt;
}
</code></pre>

<p>Index ActionResult in CustomersController:</p>

<pre><code>public ActionResult Index()
{
    if (searchBy == "Company")
    {
        return View(db.Customers
          .Where(x =&gt; x.Company.Contains == Search || Search == null).ToList());
    }
    else
    {
        return View(db.Customers.Where(x =&gt; x.LastName.StartsWith(Search)).ToList());
    }
}
</code></pre>

<p>Any help would be much appreciated. Thanks.</p>