如何防止 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
}
}
谢谢, -基思
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,添加一个新的 { target = "_self" } 作为 htmlAttributes 对象对我有用,如
for this adding a new { target = "_self" } as htmlAttributes object worked for me as in