型号:
[Required]
[StringLength(200, ErrorMessageResourceType = typeof(Resources.Messages), ErrorMessageResourceName = "ErrorMessageResourceName_StringLengthMax")]
[Display(Name = "Profile_City", ResourceType = typeof(Resources.Messages))]
public string City { get; set; }
查看:
@Html.LabelFor(model => model.City, htmlAttributes: new { @class = "control-label col-sm-6" })
<div class="col-sm-18">
@Html.TextBoxFor(model => model.City, htmlAttributes: new { @class = "form-control", autocomplete = "off" })
@Html.ValidationMessageFor(model => model.City, string.Empty, new { @class = "text-danger" })
</div>
的Global.asax:
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies["language"];
if (cookie != null && cookie.Value != null)
{
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cookie.Value);
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(cookie.Value);
}
else
{
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
}
}
Cookie值可以是de-DE或en-US
当我测试应用程序并忘记写一个城市时的问题:
本地语言与DE语言:
错误信息是&#34; Das Feld&#34; Stadt&#34; ist erforderlich。&#34; (OK)
美国本地语言:
错误消息是&#34;城市字段是必需的。&#34; (OK)
远程美国语言:
错误消息是&#34;城市字段是必需的。&#34; (OK)
用DE语言远程:
错误消息是&#34; Stadt字段是必需的。&#34; (不好)
这是英语和德语的混合。 &#34;施塔特&#34;是德国人,这是好的。但是&#34; ......字段是必需的&#34;是英语。
如果我写的字母数超过200个而不是StringLength Validator在德语中用远程DE语言显示正确的错误消息。
我使用jquery 1.10.2和jQuery Validation Plugin 1.11.1
我是否需要手动编写必需的消息?对于Local,一切都会自动运行。