我需要幾個輸入字段以下驗證:在mvc表單上添加輸入驗證的最佳方法?
01 - Unicode String. No line breaks or tabs. DATA_MAX_LENGTH applies.
02 - Unicode Memo. Line breaks permitted. No tabs. DATA_MAX_LENGTH applies.
03 - Non-negative integer, as string.
04 - Non-negative Money (precision 18,2), as string.
05 - Date, as string, in the U.S. 4-digit-year format (e.g. 12/31/2012).
06 - Boolean (aka "Bit", "Yes/No"), as string, with "1" for True, "0" for False.
是否有提供所有這些驗證(或可擴展),或將使用幾個插件是一個好主意,一個jQuery插件。我正在使用MVC3,我需要它們用於表單上的動態控件。
我的模型的問題(這些問題將用於動態測驗形式創建):
public class Question
{
public int QuestionID { get; set; }
public string QuestionText { get; set; }
public Nullable<bool> Required { get; set; }
public int DisplayOrder { get; set; }
public int StepID { get; set; }
public Nullable<int> DataType { get; set; } // validation relate here (1-6)
public Nullable<int> ControlType { get; set; }
public string Choices { get; set; }
public Nullable<int> MaxLength { get; set; }
}
使用[dataannotations](http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.aspx) –
由於存在動態控件,因此無法使用數據註釋。 – Chaka