我已经使用 RemoteAttribute 定义了模型上两个字段的验证。每个文本框的值都成功发送到服务器,但在每个实例中作为不同的命名对象。这是一个很好的默认值,但我想为许多字段重复使用相同的远程方法。如何告诉MVC将 PrimaryEmail 和 SecondaryEmail 绑定/映射到 电子邮件<服务器端的/ em> 属性?
试过这个并且不起作用:(电子邮件始终为空)
型号:
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