I have the view below:
@Html.LabelFor(m => m.CompanyPostCode)
@Html.TextBoxFor(m => m.CompanyPostCode)
@Html.LabelFor(m => m.CompanyCity)
@Html.TextBoxFor(m => m.CompanyCity)
@Html.HiddenFor(m => m.CompanyCityID)
All attributes are marked as [Required] in my view model. Then problem is that my CompanyCityID (marked as Required) is hidden and thus no validation is done in the view. If I show this attribute in my view the validation is done.
My question: is it possible to perform a validation on a hidden field? A workaround exist?
It may seems a little strange to validate a hidden field. The reason is that this field is filled from jQuery based on special rules. If it is not filled, I know something is not valid on the view.
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…