I am using Asp.net MVC 3 and Twitter Bootstrap. What I want is to integrate both of them. The big problem for me is forms. I am using the HtmlHelper
and it is a pro
I took the liberty and created an extension method that encapsulates the code from Sherbrow to render the error class when the field is not valid. This extension method has the advantage that it is strongly-typed and shorter to write:
public static MvcHtmlString ModelStateFor(this HtmlHelper html, Expression> expression)
{
var modelMetadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData);
if (html.ViewData.ModelState.IsValidField(modelMetadata.PropertyName))
{
return MvcHtmlString.Empty;
}
return new MvcHtmlString("error");
}