0

Want to set an attribute for a field in my table for the input to the limited two "S" or "P".

I cannot find how you would do that. I applied your StringRangeAttribute class and it works beautifully when I enter a valid answer. But if I put in a dummy incorrect response to test it, it returns the prompt requiring a valid response but empties a navigation property of a different field on the same page. I can then enter the correct response but I can't save because I can't enter anything into the navigation property . I'm sure it is when isvalid is false but I don't understand what's happening nor can I find the problem.

    if (AllowableValues?.Contains(value?.ToString()) == true)
        {
            return ValidationResult.Success;
        }

        var msg = $"Please enter one of the allowable values:                                     
        {string.Join(", ", (AllowableValues ?? new string[] { "No 
        allowable 
        values found" }))}.";
        return new ValidationResult(msg);
    }
STINGEO
  • 5
  • 3
  • Can we see an example of what your code looks like please? – stwilz Apr 13 '19 at 00:29
  • Possible duplicate of [Validate model on specific string values](https://stackoverflow.com/questions/32987119/validate-model-on-specific-string-values) – KevinB Apr 14 '19 at 19:42

1 Answers1

0

You have to create a custom ValidationAttribute. Here is an answer that will help you.

KevinB
  • 16
  • 3