gpt4 book ai didi

asp.net-mvc-3 - 在 MVC3 中使用远程验证时的空值

转载 作者:行者123 更新时间:2023-12-04 06:10:38 26 4
gpt4 key购买 nike

我遇到了远程验证问题。

我有一个带有属性的 View 模型,我在该属性上添加了一个远程验证器,但是当我运行表单并在文本框中输入一个字符串时,传递给 Controller ​​的值为空。

viewmodel 中的属性如下所示:

[Required(ErrorMessage = "Enter the host's name")]
[Remote("ValidateHostFullName", "BoardroomBooking", ErrorMessage = "Enter a different name")]
[DisplayName("Host's Name")]
public string HostFullName { get; set; }

Controller 中验证器的代码如下所示:
public ActionResult ValidateHostFullName([Bind(Prefix="BookingReceptionViewModel")]string HostFullName)
{
if (!HostFullName.Equals("John Smith"))
{
return Json(true, JsonRequestBehavior.AllowGet);
}

return Json("{0} is not allowed", JsonRequestBehavior.AllowGet);
}

无论在框中键入什么,HostFullName 的字符串值都显示为 null。我已经尝试过使用和不使用绑定(bind)前缀,这没有区别。

我已经在模型上尝试过它并且它有效,它似乎只有在我使用 View 模型时才会出现问题。

谢谢

标记

最佳答案

我遇到了同样的问题。进入ValidateHostFullName()的参数必须与输入名称相同。

关于asp.net-mvc-3 - 在 MVC3 中使用远程验证时的空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7824202/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com