views:

117

answers:

1

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

A: 

You can change your controller code to:

public class UserController : Controller
{
    [AcceptVerbs(HttpVerbs.Post)]
    public void ForgotPassword(string Username)
    {    
        //TODO:  some work
    }
}

I copied your code and everything works fine for me. Shouldn't it be Ajax.BeginForm("ForgotPassword", "User" instead of Ajax.BeginForm("Log", "User" in code?

LukLed