我正在尝试在客人未查看性别广播时显示此消息“O camposexoéobrigatório”,但我得到的只是显示:“模型字段是必需的。”
代码在这里:
// GenderEnum.cs
namespace Diorama.Site.Models
{
public enum GenderEnum
{
Male,
Female
}
}
// RegisterViewModel.cs
[Required(ErrorMessage = "O campo sexo é obrigatório")]
[Name("Moça ou rapaz?")]
public GenderEnum Gender { get; set; }
public static void Map()
{
Mapper.CreateMap<RegisterViewModel, User>()
.ForMember(u => u.Gender,
opt => opt.MapFrom(r => r.Gender.ToString()[0]));
Mapper.CreateMap<User, RegisterViewModel>()
.ForMember(r => r.Gender,
o => o.MapFrom(u =>
u.Gender.ToLower() == "M"
? GenderEnum.Male
: GenderEnum.Female));
}
//_RegisterForm.cshtml
<div class="controls">
@Html.EditorFor(model => model.Gender)
@Html.ValidationMessageFor(model => model.Gender, ""
, new { @class = "help-block" })
</div>