0

I can't seem to manage to put a new css in a validationMessageFor in my Ajax form...

 @using (Ajax.BeginForm(new AjaxOptions { HttpMethod = "POST", OnSuccess = "Success", OnFailure = "Fail" }))
{

<div class="separaror">
    <div class="line1">
        @Html.LabelFor(m => m.Name)
        <br />
        @Html.TextBoxFor(m => m.Name)

            @Html.ValidationMessageFor(m => m.Name)

    </div>

    <div class="linha2">
        <br>
        <input type="submit" value="Save" />
        <input type="button" id="btnCancel" value="Cancel" />
    </div>
</div>

}

My css

.field-validation-error {
color: #e80c4d;
font-weight: bold;
}

.field-validation-valid {
display: none;
}

input.input-validation-error {
border: 1px solid #e80c4d;
}

input[type="checkbox"].input-validation-error {
border: 0 none;
}

.validation-summary-errors {
color: #e80c4d;
font-weight: bold;
font-size: 1.1em;
}

.validation-summary-valid {
display: none;
}

It doesn't override.. Why is that? Any help would be appreciated! I copied the css directly from the default Asp MVC 4 application from visual studio, I have no idea why this doesnt work. The application I'm doing is not the default application from mvc 4, so there must be something I'm missing

1 Answer 1

3

You need to set .input-validation-error for validation for inputs

This is how you do it

.input-validation-error{ background: pink; border: 1px solid red; }

If you style up the .field-validation-error it will change the validation error message(s).

.field-validation-error{ color: red; font-weight: bold; }

Hope it helps

Sign up to request clarification or add additional context in comments.

2 Comments

I put this css , but it's not overriding the validationMessageFor and textBoxFor on the form, there's something elso to be done?
The only problem is that It has to be on the same file of the form.. that's weird

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.