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?
if ($('#TextBoxID').val() == '') {
$('#TextBoxID').css('border-color', 'red');
}
else {
$('#TextBoxID').css('border-color', '');
}