1

我已经使用RemoteAttribute定义了模型上两个字段的验证。每个文本框的值都成功发送到服务器,但在每个实例中作为不同的命名对象。这是一个很好的默认值,但我想为多个字段重复使用相同的远程方法。如何告诉 MVC 将PrimaryEmailSecondaryEmail绑定/映射到服务器端的电子邮件属性?

试过这个,它不起作用:(电子邮件始终为空)

模型:

public class UserModel {
    [Remote("EmailCheck", "Profile", HttpMethod = "post", ErrorMessage = "The email is already in use.")]
    public string PrimaryEmail { get; set; }
    [Remote("EmailCheck", "Profile", HttpMethod = "post", ErrorMessage = "The email is already in use.")]
    public string SecondaryEmail { get; set; }
}

服务器端操作:

public JsonResult EmailCheck([Bind(Include = "PrimaryEmail, SecondaryEmail")]string email)
{
    return Json(!_serviceManager.UserProfileService.IsEmailInUse(email));
}

JSON发送到服务器:

PrimaryEmail=abc%40yahoo.com
SecondaryEmail=abc%40yahoo.com
4

0 回答 0