我有一个带有单个输入和按钮的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
答案 0 :(得分:2)
为此添加一个新的{target =“_ self”}作为htmlAttributes对象为我工作,如
<% using (Ajax.BeginForm("Log", "User", null, new AjaxOptions {HttpMethod = "POST" }, new { target = "_self" }))
{%>