I'm trying to implement a basic search page in the web app I'm developing. Right now the page looks like this
When a user enters a last name, the controller gets called to search the backend Microsoft SQL Server database for all accounts with that Last name
Right now the HTML form looks like this
@using (Html.BeginForm("SearchAct", "HomeController", FormMethod.Post))
{
<form>
<div>
Last Name:<br>
<input type="text" id="nameToFind">
<input type="button" id="submitId" value="submit" />
</div>
</form>
}
It's supposed to call this controller
[HttpPost]
public void SearchAct()
{
Console.WriteLine();
}
which will eventually execute the search and then put the results on the page. However, I can't get the controller to be called. I set a break point on the WriteLine so I know its never getting there and I don't know what I'm doing wrong

FormMethod.Getrather than Post. You need a parameter in the method to bind to - saypublic ActionResult SearchAct(string searchText)and the input must have a matchingnameattribute -name="SearchText"(but you will find this a lot easier if you use a view model and strongly bind to it using@Html.TextBoxFor(m = m.SearchText). And you method needs to beActionResultand return something. And assuming itsHomeControllerand notHomeControllerController- then the 2nd paraeter ofBeginForm()is"Home"