2012-03-20 121 views
0

我在我的應用程序上使用了帶有剃鬚刀視圖引擎的asp.net MVC 3。在asp.net中本地化類型驗證MVC3 + Razor

發生的是,例如,當我的模型有一個日期字段,有人寫的東西是不是一個有效的日期Ø得到這樣的消息「值‘ASD’是無效的起始日期」,

我不知道如何本地化這個消息,例如葡萄牙語「Datainálida」。

有人可以幫忙嗎?

回答

0

您必須在Model類上設置正確的屬性。像這樣:

[Date(ErrorMessageResourceName = "RequiredStar", ErrorMessageResourceType = typeof(Properties.Resources))] 
[Required(AllowEmptyStrings = false, ErrorMessageResourceName = "RequiredStar", ErrorMessageResourceType = typeof(Properties.Resources))] 
[DataType(DataType.DateTime)] 
[Display(Name = "Birthday", ResourceType = typeof(Properties.Resources))] 
[UIHint("Date")] 
public DateTime Birthday { get; set; } 
+0

找不到您的日期屬性! – 2012-03-20 12:22:04

+1

你有nuget嗎?將額外的DataAnnotation屬性作爲nuget包下載。查找包DataAnnotationsExtensions和DataAnnotationsExtensions.MVC3。項目頁面:http://dataannotationsextensions.org/ – 2012-03-20 12:37:16

+0

如果解決方案有效,請不要忘記將帖子標記爲答案。 – 2012-03-20 13:14:13