A.Dara
A.Dara

Reputation: 784

What is the best way for validate a hidden field in a mvc page?

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

Answers (1)

Darin Dimitrov
Darin Dimitrov

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

Related Questions