模型如何擴展RemoteAttribute以進入ModelState?
[Remote("ValidateDuplicateUsername", "Account", ErrorMessage = "Username is already taken")]
public string Username { get; set; }
控制器
ModelState.IsValid
的RequiredAttribute
自動如果該字段是無效的添加條目ModelState
。 然後它在視圖中顯示錯誤消息。
我怎樣才能做到這一點使用RemoteAttribute
?所以當我調用ModelState.IsValid時,它也驗證遠程驗證?
「...數據註釋被設計爲獨立於MVC ...」爲什麼在System.Web.Mvc命名空間中駐留RemoteAttribute?在WPF中,您不使用這種屬性。有這個IDataErrorInfo。更好地堅持asp.net mvc Darin ;-) – Elisabeth 2012-05-30 19:30:07
Remote屬性是一個特定的ASP.NET MVC驗證屬性:它使用客戶端JavaScript,這在其他應用程序(如WPF)中沒有任何意義。 – 2012-05-30 19:31:34
好吧,因爲你在上面的赫赫寫了你的解決方案。順便說一句。你是一個問答者:P – Elisabeth 2012-05-30 19:32:30