2014-03-06 22 views
0

我在我的視圖模型是這樣的錯誤消息:如何顯示從DataAnnotationsExtensions而不是DataAnnotations

using System.Web; 
using System.ComponentModel.DataAnnotations; 
using DataAnnotationsExtensions; 

namespace Project.Models.ViewModels 
{ 
    public class AddViewModel 
    { 
     [Integer(ErrorMessage="ID must be an integer.")] 
     public int ID { get; set; } 
    } 
} 

但是當我運行該程序,顯示錯誤消息將是」字段ID必須是數字「。我認爲這是從System.ComponentModel.DataAnnotations。如何顯示使用DataAnnotationsExtensions創建的錯誤消息? TIA。

回答

0

嘗試在全局文件

DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false; 
+0

來設置該屬性在Global.asax中?試圖添加它,但沒有工作:( – user3350025

相關問題