1- using ServiceStack . Text ;
1+ using System . Collections . Generic ;
2+ using System . Web ;
3+ using ServiceStack . Web ;
24
35namespace ServiceStack . Html
46{
@@ -15,5 +17,110 @@ public static MvcHtmlString AsRaw<T>(this T model)
1517 return MvcHtmlString . Create (
1618 ( model != null ? model : default ( T ) ) ? . ToString ( ) ) ;
1719 }
20+
21+ public static IRequest GetRequest ( this HtmlHelper html ) => html . HttpRequest ;
22+
23+ public static HtmlString ToHtmlString ( this string str ) => str == null ? MvcHtmlString . Empty : new HtmlString ( str ) ;
24+
25+ public static object GetItem ( this HtmlHelper html , string key ) =>
26+ html . GetRequest ( ) . GetItem ( key ) ;
27+
28+ public static ResponseStatus GetErrorStatus ( this HtmlHelper html ) =>
29+ ViewUtils . GetErrorStatus ( html . GetRequest ( ) ) ;
30+
31+ public static bool HasErrorStatus ( this HtmlHelper html ) =>
32+ ViewUtils . HasErrorStatus ( html . GetRequest ( ) ) ;
33+
34+ public static string Form ( this HtmlHelper html , string name ) => html . GetRequest ( ) . FormData [ name ] ;
35+ public static string Query ( this HtmlHelper html , string name ) => html . GetRequest ( ) . QueryString [ name ] ;
36+
37+ public static string FormQuery ( this HtmlHelper html , string name ) =>
38+ html . HttpRequest . FormData [ name ] ?? html . HttpRequest . QueryString [ name ] ;
39+
40+ public static string [ ] FormQueryValues ( this HtmlHelper html , string name ) =>
41+ ViewUtils . FormQueryValues ( html . GetRequest ( ) , name ) ;
42+
43+ public static string FormValue ( this HtmlHelper html , string name ) =>
44+ ViewUtils . FormValue ( html . GetRequest ( ) , name , null ) ;
45+
46+ public static string FormValue ( this HtmlHelper html , string name , string defaultValue ) =>
47+ ViewUtils . FormValue ( html . GetRequest ( ) , name , defaultValue ) ;
48+
49+ public static string [ ] FormValues ( this HtmlHelper html , string name ) =>
50+ ViewUtils . FormValues ( html . GetRequest ( ) , name ) ;
51+
52+ public static bool FormCheckValue ( this HtmlHelper html , string name ) =>
53+ ViewUtils . FormCheckValue ( html . GetRequest ( ) , name ) ;
54+
55+ public static string GetParam ( this HtmlHelper html , string name ) =>
56+ ViewUtils . GetParam ( html . GetRequest ( ) , name ) ;
57+
58+ public static string ErrorResponseExcept ( this HtmlHelper html , string fieldNames ) =>
59+ ViewUtils . ErrorResponseExcept ( html . GetErrorStatus ( ) , fieldNames ) ;
60+
61+ public static string ErrorResponseExcept ( this HtmlHelper html , ICollection < string > fieldNames ) =>
62+ ViewUtils . ErrorResponseExcept ( html . GetErrorStatus ( ) , fieldNames ) ;
63+
64+ public static string ErrorResponseSummary ( this HtmlHelper html ) =>
65+ ViewUtils . ErrorResponseSummary ( html . GetErrorStatus ( ) ) ;
66+
67+ public static string ErrorResponse ( this HtmlHelper html , string fieldName ) =>
68+ ViewUtils . ErrorResponse ( html . GetErrorStatus ( ) , fieldName ) ;
69+
70+
71+ /// <summary>
72+ /// Alias for ServiceStack Html.ValidationSummary() with comma-delimited field names
73+ /// </summary>
74+ public static HtmlString ErrorSummary ( this HtmlHelper html , string exceptFor ) =>
75+ ViewUtils . ValidationSummary ( html . GetErrorStatus ( ) , exceptFor ) . ToHtmlString ( ) ;
76+ public static HtmlString ValidationSummary ( this HtmlHelper html ) =>
77+ ViewUtils . ValidationSummary ( html . GetErrorStatus ( ) , null ) . ToHtmlString ( ) ;
78+
79+ public static HtmlString ValidationSummary ( this HtmlHelper html , ICollection < string > exceptFields ) =>
80+ ViewUtils . ValidationSummary ( html . GetErrorStatus ( ) , exceptFields , null ) . ToHtmlString ( ) ;
81+
82+ public static HtmlString ValidationSummary ( this HtmlHelper html , ICollection < string > exceptFields , Dictionary < string , object > divAttrs ) =>
83+ ViewUtils . ValidationSummary ( html . GetErrorStatus ( ) , exceptFields , divAttrs ) . ToHtmlString ( ) ;
84+ public static HtmlString ValidationSummary ( this HtmlHelper html , ICollection < string > exceptFields , object divAttrs ) =>
85+ ViewUtils . ValidationSummary ( html . GetErrorStatus ( ) , exceptFields , divAttrs . ToObjectDictionary ( ) ) . ToHtmlString ( ) ;
86+
87+ public static HtmlString HiddenInputs ( this HtmlHelper html , IEnumerable < KeyValuePair < string , string > > kvps ) =>
88+ ViewUtils . HtmlHiddenInputs ( kvps . ToObjectDictionary ( ) ) . ToHtmlString ( ) ;
89+ public static HtmlString HiddenInputs ( this HtmlHelper html , IEnumerable < KeyValuePair < string , object > > kvps ) =>
90+ ViewUtils . HtmlHiddenInputs ( kvps ) . ToHtmlString ( ) ;
91+ public static HtmlString HiddenInputs ( this HtmlHelper html , object kvps ) =>
92+ ViewUtils . HtmlHiddenInputs ( kvps . ToObjectDictionary ( ) ) . ToHtmlString ( ) ;
93+
94+ public static HtmlString FormTextarea ( this HtmlHelper html , object inputAttrs ) =>
95+ FormControl ( html , inputAttrs . ToObjectDictionary ( ) , "textarea" , null ) ;
96+ public static HtmlString FormTextarea ( this HtmlHelper html , Dictionary < string , object > inputAttrs ) =>
97+ FormControl ( html , inputAttrs , "textarea" , null ) ;
98+ public static HtmlString FormTextarea ( this HtmlHelper html , object inputAttrs , InputOptions inputOptions ) =>
99+ FormControl ( html , inputAttrs . ToObjectDictionary ( ) , "textarea" , inputOptions ) ;
100+ public static HtmlString FormTextarea ( this HtmlHelper html , Dictionary < string , object > inputAttrs , InputOptions inputOptions ) =>
101+ FormControl ( html , inputAttrs , "textarea" , inputOptions ) ;
102+
103+ public static HtmlString FormSelect ( this HtmlHelper html , object inputAttrs ) =>
104+ FormControl ( html , inputAttrs . ToObjectDictionary ( ) , "select" , null ) ;
105+ public static HtmlString FormSelect ( this HtmlHelper html , Dictionary < string , object > inputAttrs ) =>
106+ FormControl ( html , inputAttrs , "select" , null ) ;
107+ public static HtmlString FormSelect ( this HtmlHelper html , object inputAttrs , InputOptions inputOptions ) =>
108+ FormControl ( html , inputAttrs . ToObjectDictionary ( ) , "select" , inputOptions ) ;
109+ public static HtmlString FormSelect ( this HtmlHelper html , Dictionary < string , object > inputAttrs , InputOptions inputOptions ) =>
110+ FormControl ( html , inputAttrs , "select" , inputOptions ) ;
111+
112+ public static HtmlString FormInput ( this HtmlHelper html , object inputAttrs ) =>
113+ FormControl ( html , inputAttrs . ToObjectDictionary ( ) , "input" , null ) ;
114+ public static HtmlString FormInput ( this HtmlHelper html , Dictionary < string , object > inputAttrs ) =>
115+ FormControl ( html , inputAttrs , "input" , null ) ;
116+ public static HtmlString FormInput ( this HtmlHelper html , object inputAttrs , InputOptions inputOptions ) =>
117+ FormControl ( html , inputAttrs . ToObjectDictionary ( ) , "input" , inputOptions ) ;
118+ public static HtmlString FormInput ( this HtmlHelper html , Dictionary < string , object > inputAttrs , InputOptions inputOptions ) =>
119+ FormControl ( html , inputAttrs , "input" , inputOptions ) ;
120+
121+ public static HtmlString FormControl ( this HtmlHelper html , object inputAttrs , string tagName , InputOptions inputOptions ) =>
122+ ViewUtils . FormControl ( html . GetRequest ( ) , inputAttrs . ToObjectDictionary ( ) , tagName , inputOptions ) . ToHtmlString ( ) ;
123+ public static HtmlString FormControl ( this HtmlHelper html , Dictionary < string , object > inputAttrs , string tagName , InputOptions inputOptions ) =>
124+ ViewUtils . FormControl ( html . GetRequest ( ) , inputAttrs , tagName , inputOptions ) . ToHtmlString ( ) ;
18125 }
19126}
0 commit comments