Reputation: 784
How can I enforce Form to validate a hidden field in a MVC page?
it is my View:
@Html.HiddenFor(model => model.t)
@Html.ValidationMessageFor(model => model.t)
Upvotes: 2
Views: 843
Reputation: 1039050
Hidden fields are excluded from validation. On the other hand you could use a normal field that you would simply visually hide in your CSS:
@Html.TextBoxFor(model => model.t, new { @class = "hidden" })
@Html.ValidationMessageFor(model => model.t)
and in your CSS:
.hidden {
display: none;
}
Upvotes: 2