views:

27

answers:

1

I have something like this

<%using (Html.BeginForm("X", "Y", FormMethod.Post, new { id="Z" })) { %>
    <table align="center" style="width:70%;margin-bottom:15px;" cellspacing="5px";>
        <tr>
            <td width="40%">Nr.:</td>
            <td width="60%"><%=Html.TextBox("Nr", Model.Nr, new { width = 130, maxlength = 10 })%></td>
        </tr>

..............

Nr property is double (no attributes on it) so it is 0.0 when new Model object or a doble when i edit. When i edit i get the value in it(no class on it) when i add instead of 0.0 i see "null" in it and with that class on it (i removed all js from the Scripts folder i only have jquery and jquery vsdoc) This is the only field i get that class on and i can't figure it why. I don't have any other control with that id on the page. Help please!

A: 

The input-validation-error class is generated by the built-in MVC validation. I think this class' CSS is in the Site.css file in the Content folder when using the MVC Web Application template. Scroll down to the section that looks like this:

/* Styles for validation helpers
-----------------------------------------------------------*/
.field-validation-error
{
    color: #ff0000;
}

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

.input-validation-error
{
    border: 1px solid #ff0000;
    background-color: #ffeeee;
}

After an invalid model posts, the invalid fields will have this style by default--a red border with a light red background.

David
i deleted all of those from the first place . I get no borders just that the textbox has value="null" class="input-validation-error".
gigi
Can you show us the controller code? If you want to remove the input-validation-error class, you might need to write an extension Html.TextBoxFor method with a new signature, or write another in your own namespace.
David