2014-09-04 55 views

回答

2

模型驗證功能(如StringLengthAttribute)是System.ComponentModel.DataAnnotations命名空間中的屬性,與實體框架無關。只需將該屬性添加到視圖模型中的屬性即可。例如

public class MyModel 
{ 
    [StringLength(10, ErrorMessage="The name must be at least {1} characters"))] 
    public string Name { get; set; } 
} 
+0

讀者還應該看到https://stackoverflow.com/questions/25840603/can-i-do-asp-net-mvc-model-validation-without-a-view – Emilio 2014-09-22 22:28:11

相關問題