@@ -106,18 +106,34 @@ public static HtmlString HasErrorFor<TModel, TProperty>(this HtmlHelper<TModel>
106106
107107 public static HtmlString ShowLabelFor < TModel , TProperty > ( this HtmlHelper < TModel > html , Expression < Func < TModel , TProperty > > expression )
108108 {
109- return ShowLabelFor ( html , expression , labelText : null ) ;
109+ return ShowLabelFor ( html , expression , labelText : null , isrequired : false ) ;
110110 }
111111
112- public static HtmlString ShowLabelFor < TModel , TProperty > ( this HtmlHelper < TModel > html , Expression < Func < TModel , TProperty > > expression , string labelText )
112+ public static HtmlString ShowLabelFor < TModel , TProperty > ( this HtmlHelper < TModel > html , Expression < Func < TModel , TProperty > > expression , bool isrequired )
113+ {
114+ return ShowLabelFor ( html , expression , labelText : null , isrequired ) ;
115+ }
116+
117+ public static HtmlString ShowLabelFor < TModel , TProperty > ( this HtmlHelper < TModel > html , Expression < Func < TModel , TProperty > > expression , string labelText , bool isrequired )
113118 {
114119 var metadata = ModelMetadata . FromLambdaExpression ( expression , html . ViewData ) ;
115120 var propertyName = metadata . PropertyName . ToLower ( ) ;
116121
117- return html . LabelFor ( expression , labelText , new
122+ if ( isrequired )
118123 {
119- id = $ "{ propertyName } -label"
120- } ) ;
124+ return html . LabelFor ( expression , labelText , new
125+ {
126+ id = $ "{ propertyName } -label",
127+ @class = "required"
128+ } ) ;
129+ }
130+ else
131+ {
132+ return html . LabelFor ( expression , labelText , new
133+ {
134+ id = $ "{ propertyName } -label"
135+ } ) ;
136+ }
121137 }
122138
123139 public static HtmlString ShowPasswordFor < TModel , TProperty > ( this HtmlHelper < TModel > html , Expression < Func < TModel , TProperty > > expression )
0 commit comments