存在多语言应用程序,因为我们面临错误消息资源类型的问题。
错误消息数据注释无法按照当前区域性工作。
我们有英语和西班牙文化文件。
模型:
public class MyModel
{
[DataType(DataType.EmailAddress)]
[Required(ErrorMessageResourceType = typeof(MyLang.Resource), ErrorMessageResourceName = "emailrequired")]
[Display(Name = "Email", ResourceType = typeof(MyLang.Resource))]
public string Email { get; set; }
}
当我使用代码级别更改文化时,所有标题都正确更改,但错误消息未转换为正确的语言。
代码:
string cultureName="en"; // or es
Thread.CurrentThread.CurrentCulture = new CultureInfo(cultureName);
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
看法
<div class="form-group row">
<div class="col-md-2">
@Html.LabelFor(x => x.Email, new { @class = "form-control-label" })
</div>
<div class="col-md-4">
@Html.TextBoxFor(model => model.Email, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Email)
</div>
</div>