Add error message to @Html.ValidationSummary

后端 未结 2 695
梦如初夏
梦如初夏 2021-02-02 09:47

I\'m using standard MVC3 Razor views with unobtrusive Javascript validation, using @Html.ValidationSummary to show them at the top of the form. If the standard vali

2条回答
  •  南旧
    南旧 (楼主)
    2021-02-02 10:23

    You can do so just adding the Error Message to the ModelState should display the error message for you, provided that you have ValidationSummary() called on your view.

    To add the error to the ModelState just do this:

    ModelState.AddModelError("ColumnNameOrErrorMessageKeyInState","error message goes here")
    

提交回复
热议问题