MVC表单操作方法被覆盖

时间:2015-06-04 11:16:42

标签: asp.net-mvc-4 c#-4.0 razor asp.net-mvc-5.2

我有以下剃须刀形式:

@model
@using (Html.BeginForm("ResetPassword", "User", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
    @Html.AntiForgeryToken()
    @Html.Hidden("guid", ViewData["guid"]) ....ect it contains a model and 1 hidden field

当我点击页面时,我必须传递一个guid,我按照以下方式执行此操作:

User/ResetPassword/8C5F38CC-C8DB-46B4-80F5-169699D8A583

我按预期点击了动作控制器:

 public ActionResult ResetPassword(string id)
        {
            ViewBag.Title = @DDHelper.GetContent("user_password_reset_new") + " " +
                @DDHelper.GetContent("slogan") + " " + @DDHelper.GetMeta("sitename");

            if (id != null)
            {
                Guid pwID = new Guid();
                if (Guid.TryParse(id, out pwID))
                {
                    if (UserManager.GetResetPasswordUser(pwID) != null)
                    {
                        ViewData["guid"] = id;
                        return View(new Models.User());
                    }
                }
            }
            return View();
        }

现在,当我看到生产的html razor时,我看到了:

<form action="/User/ResetPassword/8C5F38CC-C8DB-46B4-80F5-169699D8A583" class="form-horizontal" method="post" role="form">

当我发布表格时,我想点击动作:

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ResetPassword(Models.User pwUser)
{
    string guid = Request["guid"];
    string password = pwUser.Password;

    Guid pwID = new Guid();

    if (Guid.TryParse(guid, out pwID))
    {             
        UserManager.ResetUserPassword(password,pwID);
        return RedirectToAction("LogOn");
    }

    return View(guid);
}

现在,当我发布表单时,我再次点击了cshtml而我没有按照我的行动进行操作

/User/ResetPassword/8C5F38CC-C8DB-46B4-80F5-169699D8A583

不存在,每当有人点击此页面时,guid就不同了。 我如何告诉html.beginform不在动作名称中写入参数?为什么剃刀表现得像这样?

0 个答案:

没有答案