Nick Gilbert Nick Gilbert - 1 year ago 73
ASP.NET (C#) Question

ASP.NET MVC Form: Can submit with ENTER key but not Submit button

I'm trying to implement a simple search form in ASP.NET MVC. Right now my cshtml looks like this

@using (Html.BeginForm("SearchDemo", "Home", FormMethod.Post))
Last Name:<br>
<input type="text" id="nameToFind" name="nameToFind">

<input type="button" id="submitId" name="submit" value="submit" />


And my controller looks like this

public ActionResult SearchDemo(string nameToFind)
return RedirectToAction("Register", "Account"); //Only redirecting for now to test

Pressing the submit button does not call the controller but pressing ENTER does. I'm guessing that means my click event is getting eaten by JavaScript or something so I tried to pause script execution in Chrome but realized browserlink.js is stuck in an infinite loop. Is that the problem? Either way, how can I stop the infinite loop?

Answer Source

Browser doesn't know to use this button as submit.




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download