I have an Ajax form with a single input and a button. On submit, the form should only post the entered value to an action method. My form is correctly posting to the User controller's Log method but when done, the page redirects to /User/Log.
How can I avoid this?
<% using (Ajax.BeginForm("Log", "User", null, new AjaxOptions {HttpMethod = "POST" }))
{%>
Please enter the username:
<%= Html.TextBox("Username", "")%>
<input type="submit" />
<% } %>
Here is the action method:
public class UserController : Controller
{
[AcceptVerbs(HttpVerbs.Post)]
public void ForgotPassword(FormCollection collection)
{
string username = collection["Username"];
//TODO: some work
}
}
Thanks, -Keith