2010-01-04 71 views
4

錯誤消息我使用如何從模型狀態

modelstate.Adderror("test","test message") 

,我怎麼能在控制器本身得到這個ModelState中值。

就像我需要在控制器中得到「測試」的錯誤信息。

+0

可能的重複http://stackoverflow.com/questions/573302/how-do-i-get-the-collection-of-model-state-errors-in-asp-net-mvc – 2010-01-04 09:53:49

回答

5

他請求控制器,我無法驗證這一點,但我覺得這簡直是一樣的東西:

ModelState["test"].Value 
ModelState["test"].Error 
ModelState["test"] 

其中之一以上。

+1

雅感謝,這是什麼我正在尋找.. – Santhosh 2010-01-04 10:15:01

+0

@santose,在這種情況下 - 接受答案請 – 2010-01-04 10:20:00

1

嘗試<%=Html.ValidationMessage("Test") %>