asp.net – 如何防止Ajax.BeginForm加载新页面?

我有一个带有单个输入和按钮的Ajax表单.提交时,表单应仅将输入的值发布到操作方法.我的表单正确发布到用户控制器的Log方法,但完成后,页面重定向到/ User / Log.

我怎么能避免这个?


<% using (Ajax.BeginForm("Log", "User", null, new AjaxOptions {HttpMethod = "POST" }))
{%>
    Please enter the username: 
    <%= Html.TextBox("Username", "")%>
    <input type="submit" />
<% } %>

这是动作方法:


public class UserController : Controller
{
    [AcceptVerbs(HttpVerbs.Post)]
    public void ForgotPassword(FormCollection collection)
    {
        string username = collection["Username"];

        //TODO:  some work
    }
}

谢谢,
-Keith

最佳答案 为此添加一个新的{target =“_ self”}作为htmlAttributes对象为我工作,如

<% using (Ajax.BeginForm("Log", "User", null, new AjaxOptions {HttpMethod = "POST" }, new { target = "_self" }))
{%>
点赞