如何解决C# Html.ValidationMessageFor 在表单发布时不起作用
我对验证消息有疑问。
控制器:
[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",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; }
}
其他类:
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; }
}
查看:
<div style="display: flex; align-items: center;">
@using (Html.BeginForm("OthersPass",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>
当用户点击带有错误值的按钮时,它什么都不返回。我认为问题是由 2 post 方法引起的。可能是因为 ActionResult 元素返回的值。那么问题的根源是什么?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。