How to validate Hiddenfields in MVC5

I hope you have read our last article "How to validate fields not in model class in MVC5" in which we describe how to validate fields that are not in model class. We use same validation concept to validate hiddenfields in MVC5. If your hiddenfield is field of model class then you have to add simple ValidationMessage control to show validation message, but if your hiddenfield is not a field of model then you must visit above link.

By default jquery.validate.js is ignore hidden fields to validate and that's beneficial to us, but in certain condition we can not directly validate textbox or any control and we must use hiddenfields (like store list of ids, or temp id) and have to validate it. To resolve this problem we share simple trick to validate hiddenfields and display message for it.

please visit our most interested article on MVC5

Validate Hiddenfields in MVC5

open jquery.validate.js file find ignore text, you will see below structure.
update ignore parameters as below
ignore:":hidden:Not(.IncludeHidden)" // find hidden field by class
ignore:":hidden:Not(#includeHidden)" // find hidden field by id
Example of How to Validate Hiddenfields in MVC5 application
@using (Html.BeginForm())
    <h2>Validate Hiddenfield in MVC5 </h2>
@Html.Hidden("Name", "", new { data_val = "true", data_val_required = "This is hidden field Validation Call", @class = "IncludeHidden" })
@Html.TextBox("FirstName", "", new { data_val = "true", data_val_required = "First Name is required" })
<input type="submit" name="submit" value="Submit" />