MVC: Only me or IsValidField is illogical

While I was writing some code to print JS when a field is invalid in ModelState

, came up with the following method:

ModelState.IsValidField(string key)

A comment in IntelliSense tells me:

Returns true if there is any System.Web.Mvc.ModelError associated with or prefixed with a specific key.

While I am asking if the field is valid, it will return false

in case it is invalid, and true

if it is valid.

It seems rather counterintuitive, but I haven't found any resources on the Internet to support it.

+2


source to share


2 answers


Did another simple test and actually the method behaves as it should, the description in IntelliSense is just misleading.



0


source


I think this means that this field needs to be checked, not if it is valid. although you have a point that this seems to be misleading. You may need to dig deeper for reasoning here or naming.



0


source







All Articles