2
我需要添加錯誤消息的ModelState象下面這樣:可以(或應該)我使用的ActionLink()在控制器
ModelState.AddModelError(string.Empty, string.Format("An account with the mobile or email you have specified already exists. If you have forgotten your password, please {0} it.", Html.ActionLink("Reset", "Reset", "Account")));
首先是如何做到這一點?順便說一下,在MVC模式中這樣做是適當的嗎?
或者我應該向ModelState添加一個鍵並讓視圖選取並生成錯誤消息?
我同意。現在我正在努力做到這一點;然而,仍然沒有運氣在從視圖中爲modelState中的鍵指定錯誤消息。 –
你看過模型驗證屬性嗎? –
我不認爲這可以通過屬性來實現。這是動態驗證(檢查用戶是否存在)。 –