I am trying to use a different message for @Html.ValidationMessageFor()
in ASP.NET MVC3. This works fine but it seems to make the message be always displayed , e.g. if I do this:
@Html.ValidationMessageFor(model => model.TimesheetEntry.Product)
then the error is only shown when I submit the form and it is invalid. However if I do this:
@Html.ValidationMessageFor(model => model.TimesheetEntry.Product, "custom error")
then that message is displayed as soon as I initially load the page. I'm probably doing something stupid here and any help would be appreciated.
ValidationMessageFor<TModel,TProperty>(HtmlHelper<TModel>, Expression<Func<TModel,TProperty>>, String) Returns the HTML markup for a validation-error message for each data field that is represented by the specified expression, using the specified message.
So, to clear the validation errors, you can do something like this to a form : var fieldContexts = form. __MVC_FormValidation. fields; for(i = 0; i < fieldContexts.
ValidationMessage(HtmlHelper, String) Displays a validation message if an error exists for the specified field in the ModelStateDictionary object.
Have you tried the CSS from this question?
.field-validation-valid { display: none; } .validation-summary-valid { display: none; }
probably you have model parameter in your httpGet ActionResult method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With