using IDataErrorInfo in asp.net mvc

后端 未结 3 1604
无人及你
无人及你 2020-12-16 07:09

I\'ve got a simple address entry app that I\'m trying to use the IDataErrorInfo interface as explained on the asp.net site.

It works great for items that can be val

3条回答
  •  生来不讨喜
    2020-12-16 07:51

    Regarding the comment on Error string, IDataErrorInfo and the Html.ValidationMessage, you can display object level vs. field level error messages using:

    Html.ValidationMessage("address", "Error")
    
    Html.ValidationMessage("address.PostalCode", "Error")
    

    In your controller decorate the post method handler parameter for the object with [Bind(Prefix = "address")]. In the HTML, name the input fields as such...

    
    

    I don't generally use the Html helpers. Note the naming convention between id and name.

提交回复
热议问题