@@ -26,8 +26,6 @@ public class DefaultHtmlGenerator : IHtmlGenerator
26
26
private readonly IModelMetadataProvider _metadataProvider ;
27
27
private readonly IUrlHelper _urlHelper ;
28
28
29
- public string IdAttributeDotReplacement { get ; set ; }
30
-
31
29
/// <summary>
32
30
/// Initializes a new instance of the <see cref="DefaultHtmlGenerator"/> class.
33
31
/// </summary>
@@ -43,6 +41,9 @@ public DefaultHtmlGenerator(
43
41
_urlHelper = urlHelper ;
44
42
}
45
43
44
+ /// <inheritdoc />
45
+ public string IdAttributeDotReplacement { get ; set ; }
46
+
46
47
/// <inheritdoc />
47
48
public string Encode ( string value )
48
49
{
@@ -252,32 +253,6 @@ public virtual TagBuilder GenerateLabel(
252
253
return tagBuilder ;
253
254
}
254
255
255
- /// <inheritdoc />
256
- public virtual TagBuilder GenerateOption ( SelectListItem item , string encodedText )
257
- {
258
- var tagBuilder = new TagBuilder ( "option" )
259
- {
260
- InnerHtml = encodedText ,
261
- } ;
262
-
263
- if ( item . Value != null )
264
- {
265
- tagBuilder . Attributes [ "value" ] = item . Value ;
266
- }
267
-
268
- if ( item . Selected )
269
- {
270
- tagBuilder . Attributes [ "selected" ] = "selected" ;
271
- }
272
-
273
- if ( item . Disabled )
274
- {
275
- tagBuilder . Attributes [ "disabled" ] = "disabled" ;
276
- }
277
-
278
- return tagBuilder ;
279
- }
280
-
281
256
/// <inheritdoc />
282
257
public virtual TagBuilder GeneratePassword (
283
258
[ NotNull ] ViewContext viewContext ,
@@ -725,6 +700,56 @@ public IEnumerable<ModelClientValidationRule> GetClientValidationRules(
725
700
new ClientModelValidationContext ( metadata , _metadataProvider ) ) ) ;
726
701
}
727
702
703
+ internal static string EvalString ( ViewContext viewContext , string key , string format )
704
+ {
705
+ return Convert . ToString ( viewContext . ViewData . Eval ( key , format ) , CultureInfo . CurrentCulture ) ;
706
+ }
707
+
708
+ /// <remarks>
709
+ /// Not used directly in HtmlHelper. Exposed for use in DefaultDisplayTemplates.
710
+ /// </remarks>
711
+ internal static TagBuilder GenerateOption ( SelectListItem item , string encodedText )
712
+ {
713
+ var tagBuilder = new TagBuilder ( "option" )
714
+ {
715
+ InnerHtml = encodedText ,
716
+ } ;
717
+
718
+ if ( item . Value != null )
719
+ {
720
+ tagBuilder . Attributes [ "value" ] = item . Value ;
721
+ }
722
+
723
+ if ( item . Selected )
724
+ {
725
+ tagBuilder . Attributes [ "selected" ] = "selected" ;
726
+ }
727
+
728
+ if ( item . Disabled )
729
+ {
730
+ tagBuilder . Attributes [ "disabled" ] = "disabled" ;
731
+ }
732
+
733
+ return tagBuilder ;
734
+ }
735
+
736
+ internal static string GetFullHtmlFieldName ( ViewContext viewContext , string name )
737
+ {
738
+ var fullName = viewContext . ViewData . TemplateInfo . GetFullHtmlFieldName ( name ) ;
739
+ return fullName ;
740
+ }
741
+
742
+ internal static object GetModelStateValue ( ViewContext viewContext , string key , Type destinationType )
743
+ {
744
+ ModelState modelState ;
745
+ if ( viewContext . ViewData . ModelState . TryGetValue ( key , out modelState ) && modelState . Value != null )
746
+ {
747
+ return modelState . Value . ConvertTo ( destinationType , culture : null ) ;
748
+ }
749
+
750
+ return null ;
751
+ }
752
+
728
753
protected virtual TagBuilder GenerateInput (
729
754
[ NotNull ] ViewContext viewContext ,
730
755
InputType inputType ,
@@ -843,6 +868,8 @@ protected virtual TagBuilder GenerateLink(
843
868
return tagBuilder ;
844
869
}
845
870
871
+ // Only render attributes if client-side validation is enabled, and then only if we've
872
+ // never rendered validation for a field with this name in this form.
846
873
protected virtual IDictionary < string , object > GetValidationAttributes (
847
874
ViewContext viewContext ,
848
875
ModelMetadata metadata ,
@@ -876,13 +903,6 @@ private static string EvalString(ViewContext viewContext, string key)
876
903
return Convert . ToString ( viewContext . ViewData . Eval ( key ) , CultureInfo . CurrentCulture ) ;
877
904
}
878
905
879
- // Only render attributes if client-side validation is enabled, and then only if we've
880
- // never rendered validation for a field with this name in this form.
881
- private static string EvalString ( ViewContext viewContext , string key , string format )
882
- {
883
- return Convert . ToString ( viewContext . ViewData . Eval ( key , format ) , CultureInfo . CurrentCulture ) ;
884
- }
885
-
886
906
// Only need a dictionary if htmlAttributes is non-null. TagBuilder.MergeAttributes() is fine with null.
887
907
private static IDictionary < string , object > GetHtmlAttributeDictionaryOrNull ( object htmlAttributes )
888
908
{
@@ -899,12 +919,6 @@ private static IDictionary<string, object> GetHtmlAttributeDictionaryOrNull(obje
899
919
return htmlAttributeDictionary ;
900
920
}
901
921
902
- private static string GetFullHtmlFieldName ( ViewContext viewContext , string name )
903
- {
904
- var fullName = viewContext . ViewData . TemplateInfo . GetFullHtmlFieldName ( name ) ;
905
- return fullName ;
906
- }
907
-
908
922
private static string GetInputTypeString ( InputType inputType )
909
923
{
910
924
switch ( inputType )
@@ -924,17 +938,6 @@ private static string GetInputTypeString(InputType inputType)
924
938
}
925
939
}
926
940
927
- private static object GetModelStateValue ( ViewContext viewContext , string key , Type destinationType )
928
- {
929
- ModelState modelState ;
930
- if ( viewContext . ViewData . ModelState . TryGetValue ( key , out modelState ) && modelState . Value != null )
931
- {
932
- return modelState . Value . ConvertTo ( destinationType , culture : null ) ;
933
- }
934
-
935
- return null ;
936
- }
937
-
938
941
private static IEnumerable < SelectListItem > GetSelectListItems ( [ NotNull ] ViewContext viewContext , string name )
939
942
{
940
943
var value = viewContext . ViewData . Eval ( name ) ;
0 commit comments