Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9093275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:03:27+00:00 2026-06-16T23:03:27+00:00

I am trying to validate two textboxes based on the URL that has been

  • 0

I am trying to validate two textboxes based on the URL that has been entered, the textboxes are for job title and military rank.

Generally for most of the routes I have created the job title textbox will be required only three URLs currently require military rank instead, in similar projects I have added a RequiredIf annotation using MVC Foolproof Validation which has been added to a view model, in the case I have tried using the annotation but because I am validating from a domain model project the Foolproof Validation is not working.

I have currently partially implemented custom validation in the domain model as a handler class using this code:

 if (paymentDetailsForm.UseRankInsteadOfJobTitle)
        {
            if (paymentDetailsForm.Rank == null)
            {
                yield return new ValidationResult(Resources.JobRankRequired);
            }
        }

essentially I have created a Boolean value called UseRankInsteadOfJobTitle which is set to either true or false depending on the URL entered.

to set this value as either true or false I have used this code in the controller:

if ((programme.Code == "AMAC") || (programme.Code == "AMACD") || (programme.Code == "AMACR"))
        {
            ViewData["UseRankInsteadOfJobTitle"] = true;
        }
        else
        {
            ViewData["UseRankInsteadOfJobTitle"] = false;
        }

And then created a hidden field on the view:

@Html.Hidden("UseRankInsteadOfJobTitle", @ViewData["UseRankInsteadOfJobTitle"])

the following HTML is then generated:

for false values

<input data-val="true" data-val-required="The Boolean field is required." id="UseRankInsteadOfJobTitle" name="UseRankInsteadOfJobTitle" type="hidden" value="False" />

for true values

<input data-val="true" data-val-required="The Boolean field is required." id="UseRankInsteadOfJobTitle" name="UseRankInsteadOfJobTitle" type="hidden" value="True" /> 

Currently the validation message is not being displayed for either job title or military rank, I need a way of ascertaining whether the value of USERankInsteadOfJobTitle is true or false.

I have tried using the formCollection class to get the value of the hidden field but so far this has not worked.

Any advice on how I could do this or better way of validating these textboxes would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T23:03:28+00:00Added an answer on June 16, 2026 at 11:03 pm

    Have you tried using the Request["Fieldname"]?

    Maybe something like someBoolean = Request["UseRankInsteadOfJobTitle"]?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two textboxes, with that am trying to validate like var max =
I am trying to validate that two columns are unique in my User model.
I'm trying to validate two date attributes in order that they be consecutive. The
I have a textarea that I am trying to validate whether someone has filled
I have been trying to validate my web page for the last two hours,
I am trying to validate two checkboxes. One of them must be checked in
I am trying to validate two fields. One is open time and the other
I am trying to validate the entry in a cell based on the contents
I am trying to validate a phone number which is contained over two fields.
I am trying to validate the two input boxes where the user selects a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.