表单不会发布到控制器

I'm working in asp.net MVC5. I have a page that displays a failry simple list of materials, for which a search function is needed.

For this, I used an Ajax form, taken from some small tutorial. I've used the exact same method on another page and got it working there, so I copied said code.

But now I can't get it to work for the life of me.

The problem is that query is always null. The only way I got it to be anything else is by adding ?query=ben to my url. This way I finally got to test the other functionalities of the search bar, which work just fine.

The .cshtml:

<div class="pure-form">
  @using (Ajax.BeginForm("Materiaal_Main", "Materiaal", 
    new AjaxOptions
      {
        HttpMethod = "GET",
        UpdateTargetId = "beheertable",
      }))
  {
    <input type="text" id="txtsearch" name="query" placeholder="Algemeen dynamisch zoeken..." AutoComplete="off" style="margin-bottom: 10px; position:relative; top: 3px;" value="@ViewBag.query" />
    <input type="submit" value="Search" class="ui button" />
  }
</div>

My controller:

public ActionResult Materiaal_Main(int? pageNum, string query)
{
  ViewBag.Title = "Materiaal_Main";
  ViewBag.Totaal = (from m in db.tbl_materiaal select m).Count();

  pageNum = pageNum ?? 0;
  query = query ?? "";
  ViewBag.IsEndOfRecords = false;

  if(pageNum == 0)
  {
    LoadAllMateriaalToSession();
  }

  if (Request.IsAjaxRequest())
  {
    var materiaal = GetMateriaalForPage(pageNum.Value, query);
    ViewBag.IsEndOfRecords = (materiaal.Any()) && ((pageNum.Value * LazyLoadingRows) >= materiaal.Last().Key);
    ViewBag.query = query;
    return PartialView("_MateriaalRow", materiaal);
  }
  else
  {
    ViewBag.Materiaal = GetMateriaalForPage(pageNum.Value, query);
    ViewBag.query = query;
    return View();
  }
}

Notes:

  • In this page is another form present, because users can check different materials to register them for maintenance etc. I've briefly thrown this out of the page to test interference, and it made no difference.

  • The other page (which shows a list of people) is built exactly the same as the code I provided here. This page works brilliantly.

  • Both this and the other page use lazyloading, which explains the pageNum. No need to worry about this.

ANY help is welcome, be it someone who spies a mistake, or who can offer an alternative.

It took me a long while of searching, but when I suddenly found what went wrong, I facepalmed hard.

The method wasn't working because I had a seperate [HttpPost] method of the same name, that didn't pass any values to the other function. Long story short:

public ActionResult Materiaal_Main(int? pageNum, string query)
  { ... }

[HttpPost]
public ActionResult Materiaal_Main(FormCollection form)
  {...
    return RedirectToAction("Materiaal_Main", new { query = form["query"].ToString() });
  }

fixed it.