Question Validation Messages Not Working

etkmlm

Member
Joined
Sep 14, 2020
Messages
9
Programming Experience
3-5
Hi, I have an issue with validation messages. I think the problem is caused by 2 post method.

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" }); ;
        }

Password Confirm Class:
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>

When I entered the wrong values, it did not react.
 
Back
Top Bottom