我在Asp.Net MVC 5项目中使用jquery validate不引人注目。验证使用英语,但是我希望使用其他语言,例如挪威语。
我发现messages_no.js
这里https://github.com/jzaefferer/jquery-validation/tree/master/src/localization
后列入该js文件jquery.validate.js
和jquery.validate.unobtrusive.js
。我可以在开发人员工具中看到它正确包含在页面中,但是错误消息仍然是英文。
我想念什么吗?
从data-val-
控件的html attribute()中检索错误消息。控件是Html.EditorFor
使用DataAnnotations
属性的在服务器端()生成的。
因此,例如代替
[Required(ErrorMessage = "Required")]
public string Email { get; set; }
您应该使用资源(.resx文件)
[Required(ErrorMessageResourceType = typeof(Resource), ErrorMessageResourceName = "Required"]
public string Email { get; set; }
确保Thread.CurrentThread.CurrentCulture
并Thread.CurrentThread.CurrentUICulture
设置为所需的文化。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句