我有一个只有一个输入和一个按钮的Ajax表单。在提交时,表单应该只将输入的值发送到操作方法。我的表单正确地发送到了用户控制器的Log方法,但完成后,页面将重定向到/ User /Log。
我怎样才能避免这种情况?
<% using (Ajax.BeginForm("Log", "User", null, new AjaxOptions {HttpMethod = "POST" }))
{%>
Please enter the username:
<%= Html.TextBox("Username", "")%>
<input type="submit" />
<% } %>
下面是action方法:
public class UserController : Controller
{
[AcceptVerbs(HttpVerbs.Post)]
public void ForgotPassword(FormCollection collection)
{
string username = collection["Username"];
//TODO: some work
}
}
谢谢,-Keith
发布于 2011-05-10 09:14:59
为此,我添加了一个新的{ htmlAttributes = "_self“}作为目标对象,如下所示
<% using (Ajax.BeginForm("Log", "User", null, new AjaxOptions {HttpMethod = "POST" }, new { target = "_self" }))
{%>
https://stackoverflow.com/questions/2337602
复制相似问题