验证消息不起作用

会员
已加入
2020年9月14日
留言内容
9
编程经验
3-5
嗨,我的验证讯息有问题。我认为问题是由2个发布方法引起的。

Controller:
        [HttpGet]
        [Authorize]
        public ActionResult Others(string bid)
        {
                  return View(ret);
        }

        [HttpPost]
        public ActionResult OthersUser(Others info)
        {
                 return RedirectToAction("Others", "User", new { bid = "1" });
        }

        [HttpPost]
        public ActionResult OthersPass(Others info)
        {
            if (ModelState.IsValid)
            {
              
            }
            return RedirectToAction("Others", "User", new { bid = "2" }); ;
        }

密码确认等级:
public class PassConfirm
    {
        [Key]
        public int ID { get; set; }
        public User User { get; set; }
        public virtual int UserID { get; set; }
        public string Key { get; set; }

        [Required]
        public string Password { get; set; }

        [NotMapped]
        [Compare("Password", ErrorMessage = "Passwords not matching!")]
        public string ConfirmPassword { get; set; }
    }

Others Class:
public class Others
    {
        public int BID { get; set; }

        public PassConfirm PassChg { get; set; }
        public String OldPsw { get; set; }

        public User User { get; set; }
        public string UserCheck { get; set; }


    }

View:
<div style="display: flex; align-items: center;">
                @using (Html.BeginForm("OthersPass", "User", FormMethod.Post))
                {
                    <table>
                        <tr>
                            <td><label for="oldpsw">Eski Şifre:</label></td>
                            <td>@Html.TextBoxFor(x => x.OldPsw ,new { @id = "oldpsw", @type = "password" })</td>
                        </tr>
                        <tr>
                            <td><label for="newpsw">Yeni Şifre:</label></td>
                            <td>@Html.TextBoxFor(x => x.PassChg.Password, new { @id = "newpsw", @type = "password" })</td>
                            <td>@Html.ValidationMessageFor(x => x.PassChg.Password)</td>
                        </tr>
                        <tr>
                            <td><label for="confpsw">Şifreyi Doğrula:</label></td>
                            <td>@Html.TextBoxFor(x => x.PassChg.ConfirmPassword, new { @id = "confpsw", @type = "password"})</td>
                            <td>@Html.ValidationMessageFor(x => x.PassChg.ConfirmPassword)</td>
                        </tr>
                    </table>
                    <button class="btn btn-success" formmethod="post">Onayla</button>
                }
            </div>

当我输入错误的值时,它没有反应。
 
最佳 底部