我有一个带有单个输入和一个按钮的 Ajax 表单。提交时,表单应仅将输入的值发布到操作方法。我的表单正确发布到用户 Controller 的 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
}
}
谢谢, -基思
最佳答案
为此添加一个新的 { target = "_self"} 作为 htmlAttributes 对象对我有用
<% using (Ajax.BeginForm("Log", "User", null, new AjaxOptions {HttpMethod = "POST" }, new { target = "_self" }))
{%>
关于asp.net - 如何防止 Ajax.BeginForm 加载新页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2337602/