c# - MVC Foolproof Validation RequiredIfFalse returning error incorrectly -
i'm using mvc foolproof validation library create dependent requirements:
public bool isrequired { get; set; } [requirediftrue("isrequired", errormessage = "this field required")] public int requirediftrueselectid { get; set; }
this works on client side, allowing me submit form without requirediftrueselectid
value (i.e. value 0), on [httppost]
modelstate.isvalid
returns false, , next result in immediate window:
myviewmodel.isrequired true modelstate["requirediftrueselectid"].errors[0] {system.web.mvc.modelerror} errormessage: "a value required." exception: null
i'm ensuring i'm posting value of requirediftrueselectid (as can see in first immediate window query above). why getting "a value required" message, , how can suppress error?
by way, i'm in mvc5. maybe modelstate
implementation has changed since foolproof's lastly update 2 years ago? else know of more recently-published library functions foolproof?
controller method:
[httppost] public virtual actionresult validationtest(testviewmodel vm) { //breakpoint here check modelstate.isvalid homecoming view(vm); }
oh, duh. field value type.
value types required. need create type nullable if want optional.
notice error message not same error message used in validator, that's first clue.
c# asp.net-mvc foolproof-validation
No comments:
Post a Comment