title: ASP.NET MVC BeginForm not able to post with parameter
body: <p>I have a form with a searchbox on it.  When someone types something into the search box and hits the search button I am trying ot do a post to capture the search filter and then fire off a view. </p>
  
  <p>Here is the controller code</p>
  
  <pre><code>public class SpotsController : Controller
  {
      [HttpPost]
      [AllowAnonymous]
      public ActionResult SearchSpots(string searchfilter)
      {
          //your code here....
          return Index(searchfilter);
      }
  </code></pre>
  
  <p>Here is the code from my view up until the part that is tryign to do the submit</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"/&gt;
  &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
  &lt;title&gt;@ViewBag.Title - Haunt Spotter&lt;/title&gt;
  &lt;/head&gt;
  &lt;form id="__AjaxAntiForgeryForm" action="#" method="post"&gt;&lt;@Html.AntiForgeryToken()&gt;&lt;/form&gt;
  &lt;body&gt;
  &lt;div class="navbar navbar-inverse navbar-fixed-top"&gt;
      &lt;div class="container"&gt;
          &lt;div class="navbar-header"&gt;
              &lt;button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"&gt;
                  &lt;span class="icon-bar"&gt;&lt;/span&gt;
                  &lt;span class="icon-bar"&gt;&lt;/span&gt;
                  &lt;span class="icon-bar"&gt;&lt;/span&gt;
              &lt;/button&gt;
          &lt;/div&gt;
          &lt;div class="navbar-collapse collapse"&gt;
              @using (Html.BeginForm("SearchSpots", "Spots"))
              {
                  &lt;input id="searchfilter" type="text" class="form-control" autocomplete="off" placeholder="Search" name="searchfilter"&gt;
                  &lt;button class="btn btn-default" type="submit"&gt;&lt;i class="glyphicon glyphicon-search"&gt;&lt;/i&gt;&lt;/button&gt;
              }
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>If I take the parameter off of the controller function it works fine.  If not it seems to crash and try to re display a get which fails because I only have a post function for this.  I am guessing I have something screwed up with the parameter but I can't figure out what it is.  Any help woudl be greatly appreciated.</p>
  
  <p>UPDATE</p>
  
  <p>Based on feedback I have changed my post to a get</p>
  
  <pre><code>    [HttpGet]
      [AllowAnonymous]
      public ActionResult SearchSpots(string searchfilter)
      {
          //your code here....
          return Index(searchfilter);
      }
  </code></pre>
  
  <p>and my view code to this</p>
  
  <pre><code>@using (Html.BeginForm("SearchSpots", "Spots", FormMethod.Get, null))
  {
      &lt;input id="searchfilter" type="text" class="form-control" autocomplete="off" placeholder="Search" name="searchfilter"&gt;
      &lt;button class="btn btn-default" type="submit"&gt;&lt;i class="glyphicon glyphicon-search"&gt;&lt;/i&gt;&lt;/button&gt;
  }
  </code></pre>
  
  <p>Unfortunately I still have the original issue.  If I remove the searchfileter parameter from my controller call then it goes into the call with no problems but when I am expecting the modelbinder to give me a searchfilter it crashes out.</p>
  
  <p>Here is the call I am redirecting to in my search function</p>
  
  <pre><code>private ApplicationDbContext db = new ApplicationDbContext();
  
      // GET: Spots
      public ActionResult Index(string filter = "")
      {
          ViewBag.initialFilter = filter;
          if (User.IsInRole("SiteAdmin"))
          {
              return View(db.Spots.ToList());
          }
          else
          {
              return View(db.Spots.Where(x =&gt; x.Approved).ToList());
          }
  
      }
  </code></pre>
  
  <p>and the view that is displayed</p>
  
  <pre><code>@model IEnumerable&lt;HauntSpots.Models.Spot&gt;
  
  @{
      ViewBag.Title = "Index";
  }
  
  &lt;h2 class="align-right"&gt;Haunt Spots&lt;/h2&gt;
  
  @if (Context.User.IsInRole("SiteAdmin"))
  { 
      &lt;p style="padding-top:20px"&gt;
  
      &lt;a href="@Url.Action("Create")" title="Add New Spot" class="btn btn-primary"&gt;&lt;i class="icon-plus-sign"&gt;&lt;/i&gt; Add New&lt;/a&gt;
      &lt;/p&gt;
  }
  
  &lt;table id="dt-spots" class="table table-striped"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
          &lt;th&gt;&lt;/th&gt;
          &lt;th&gt;&lt;/th&gt;
          &lt;th&gt;&lt;/th&gt;
          @if (Context.User.IsInRole("SiteAdmin"))
          {
              &lt;th&gt;&lt;/th&gt;
          }
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
  
      @foreach (var item in Model)
  {
  
          &lt;tr&gt;
              &lt;td&gt;
                  @if (Context.User.IsInRole("SiteAdmin"))
                  {
                      @Html.Hidden(Url.Action("Edit", "Spots", new { id = item.Id }))
                      &lt;a style="color: Red; vertical-align: middle; font-size: 2em" href="@Url.Action("Delete", "Spots", new { id = item.Id })" title="Delete Spot" class="btn"&gt;&lt;i class="icon-remove-sign"&gt;&lt;/i&gt;&lt;/a&gt;
                  }
                  else
                  {
                      @Html.Hidden(Url.Action("Details", "Spots", new { id = item.Id }))
                  }
              &lt;/td&gt;
              &lt;td&gt;
  
                  @if (item.Image == null)
                  {
                      &lt;img width="100" height="100"
                           src="~/Content/Images/NoPhoto.jpg" class="img-rounded" /&gt;
                  }
                  else
                  {
                      &lt;img width="100" height="100"
                           src="@item.Image" class="img-rounded"/&gt;
                  }
              &lt;/td&gt;
              &lt;td &gt;
                  &lt;div class="form-group pull-left col-md-2"&gt;
                      &lt;h4&gt;@item.Title &lt;/h4&gt;
                      &lt;h5 style="clear: left"&gt;
                          @if (item.Address != null)
                          {
                              &lt;span&gt;@item.Address&lt;/span&gt;
                              &lt;br/&gt;
                          }
  
                          @if (item.State == null)
                          {
                              &lt;span&gt;@item.City&lt;/span&gt;&lt;br/&gt;
                              &lt;span&gt;@item.Country&lt;/span&gt;
                          }
                          else
                          {
                              if (item.State == "")
                              {
                                  &lt;span&gt;@item.City&lt;/span&gt;
                                  &lt;br/&gt;
                                  &lt;span&gt;@item.Country&lt;/span&gt;
                              }
                              else
                              {
                                  &lt;span&gt;@item.City, @item.State&lt;/span&gt;
                                  &lt;br/&gt;
                                  &lt;span&gt;@item.Country&lt;/span&gt;
                              }
                          }
                      &lt;/h5&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group pull-left col-md-8"&gt;
                      &lt;h6&gt;@item.Summary&lt;/h6&gt;
                  &lt;/div&gt;
              &lt;/td&gt;
              @if (Context.User.IsInRole("SiteAdmin"))
              {
                  &lt;td&gt;
                      @if (@item.Approved)
                      {
                          &lt;span style="color: green"&gt;Approved&lt;/span&gt;
                  }
                  else
                  {
                          &lt;span style="color: red"&gt;Not Approved&lt;/span&gt;
                  }
                  &lt;/td&gt;
              }
          &lt;/tr&gt;
      }
      &lt;/tbody&gt;
  &lt;/table&gt;
  
  &lt;script type="text/javascript"&gt;
      $(document).ready(function () {
          //Initalize and configure DataTables
          $('#dt-spots').dataTable({
              "oSearch": { "sSearch": "@ViewBag.initialFilter" }
          });
  
  
          $("tbody").on("click", "tr", function () {
              window.location = $(this).find('input').attr('name');
          });
      });
  &lt;/script&gt;
  </code></pre>