Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the textbox border color red when validation fails

I have got a task to set red color border for text box when the validation fails in .net mvc 4.

BExtensionMethods.cs

    public static string GetTextBoxColor(this ModelStateDictionary ModelState)
    {
        string textBoxColor = string.Empty;
        int count = 1;
        var errorKeys = (from item in ModelState
                         where item.Value.Errors.Any()
                         select item.Key).ToList();
        foreach (var item in errorKeys)
        {
            textBoxColor += string.Format("{0}.{1}</br>", count, item);
            count++;
        }
        return textBoxColor;
    }

Here the json object contains the values.How can I filter it?

like image 747
Nithin Viswanathan Avatar asked Apr 24 '13 07:04

Nithin Viswanathan


1 Answers

if ($('#TextBoxID').val() == '') {
    $('#TextBoxID').css('border-color', 'red');
}
else {
    $('#TextBoxID').css('border-color', '');
}
like image 146
Mohan Kumar Avatar answered Oct 08 '22 02:10

Mohan Kumar