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 9247373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:42:39+00:00 2026-06-18T09:42:39+00:00

I am creating a registration form. I have a property that is a national

  • 0

I am creating a registration form. I have a property that is a national identity number. But I want the user to fill it after confirming the registration. Then I don’t write it in the registration form.

commented:

National Identity Number
<div class="editor-field">
  @Html.EditorFor(model => model.IdentityNumber)
  @Html.ValidationMessageFor(model => model.IdentityNumber)
</div>

And this is my property:

[IdentityNumber("It is not a valid identity number")]
[Required(ErrorMessage = "You have to enter your national number")]
[DisplayName("National Identity Number:")]
public string IdentityNumber { get; set; }

But this doesn’t work. I think the reason is the attributes [IdentityNumber] and [Required]. If I comment them,

public ActionResult Register(Member model)
{
    if (ModelState.IsValid)
    {
        //.....

ModelState.IsValid is false. If I uncomment them, it returns true. So where must I change something to allow it? I mean, I want the user to write his/her identity number, after registration.

In my db, the identity national number field allows null also.

Edit: Here is my attribute code:

[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property,
AllowMultiple = false, Inherited = true)]
public class IdentityNumberAttribute : ValidationAttribute, IClientValidatable
{
    private string WrongIdentityNumber;

    public IdentityNumberAttribute(string message)
        :base("Invalid an identity number")
    {
        WrongIdentityNumber = message;
    }

    private string identityNumber;
    protected override ValidationResult IsValid(object value, ValidationContext validationContext)
    {
        if (value == null)
            return new ValidationResult(WrongIdentityNumber);   

        identityNumber = value.ToString();

        if (identityNumber.Length != 11)
            return new ValidationResult(WrongIdentityNumber);

        int sum = 0;

        for (int i = 0; i < identityNumber.Length - 1; i++)
        {
            sum += Convert.ToInt32(identityNumber[i].ToString());
        }

        return sum.ToString()[1] == identityNumber[10]
                   ? ValidationResult.Success
                   : new ValidationResult(WrongIdentityNumber);
    }


    public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
    {
        ModelClientValidationRule validationRule = new ModelClientValidationRule();
        validationRule.ValidationType = "identitynumber";
        validationRule.ErrorMessage = "Invalid identity number";
        validationRule.ValidationParameters.Add("param", "");
        return new List<ModelClientValidationRule> { validationRule };

        //var rule = new ModelClientValidationRule();
        //rule.ErrorMessage = FormatErrorMessage(metadata.GetDisplayName());
        //rule.ValidationParameters.Add("identitynumber", identityNumber);     //küçük harfle yaz html kuralı
        //rule.ValidationType = "identitynumber";
        //yield return rule;
     }
}
  • 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-18T09:42:40+00:00Added an answer on June 18, 2026 at 9:42 am

    You could add this line

    ModelState.Remove("ErrorKey");//you can find the error key by stepping though your code
    if (ModelState.IsValid)
            {
              .....
    

    the “ErrorKey” will be something like “YourModelName.YourPropertyName”. Set a breakpoint and hover over ModelState and you can see all the keys.

    But you should create a view model that has only the properties you need, put your data annotations on there, and leave your domain models out of it.

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

Sidebar

Related Questions

I have such view that handles user registration. After creating new user i want
I'm creating a user registration form and after they fill in all the information
I have a registration form that I am using to register new user. No
I am creating an app that accept user info for registration but I was
I am creating a registration form, but I have got one problem only... why
In yii I am creating registration form. After successful registration I want to generate
I have a registration form that i'm creating. In my html file, I have
I'm creating a registration form using validation inside the User model such as validates_confirmation_of
I am creating an user registration form using jsp,in which there is an option
I am creating a registration form. I want to use the placeholder attribute on

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.