2
2
using System . Linq . Expressions ;
3
3
using System . Text . Encodings . Web ;
4
4
using ChameleonForms . Component ;
5
+ using ChameleonForms . Utils ;
5
6
using JetBrains . Annotations ;
6
7
using Microsoft . AspNetCore . Razor . TagHelpers ;
7
8
using Microsoft . AspNetCore . Mvc . Rendering ;
8
9
using Microsoft . AspNetCore . Mvc . ViewFeatures ;
9
- using Microsoft . Extensions . DependencyInjection ;
10
10
11
11
namespace ChameleonForms . Example
12
12
{
@@ -31,32 +31,23 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
31
31
32
32
public void ProcessInternal < TModel , TPartialModel > ( TagHelperContext context , TagHelperOutput output , Expression < Func < TModel , TPartialModel > > @for )
33
33
{
34
- var helper = ViewContext . HttpContext . RequestServices . GetRequiredService < IHtmlHelper < TModel > > ( ) ;
35
- ( helper as HtmlHelper < TModel > ) ? . Contextualize ( ViewContext ) ;
36
- var f = ViewContext . ViewData [ "ChameleonForm" ] as Form < TModel > ;
37
- var s = ViewContext . ViewData [ "ChameleonFormSection" ] as Section < TModel > ;
38
- if ( s != null )
34
+ var helper = ViewContext . GetHtmlHelper < TModel > ( ) ;
35
+ if ( helper . IsInChameleonFormsSection ( ) )
39
36
{
37
+ var s = helper . GetChameleonFormsSection ( ) ;
40
38
output . TagMode = TagMode . StartTagAndEndTag ;
41
39
output . TagName = null ;
42
40
output . Content . SetHtmlContent ( s . PartialFor ( @for , Name ) ) ;
43
41
}
44
42
else
45
43
{
44
+ var f = helper . GetChameleonForm ( ) ;
46
45
output . TagMode = TagMode . StartTagAndEndTag ;
47
46
output . TagName = null ;
48
47
output . Content . SetHtmlContent ( f . PartialFor ( @for , Name ) ) ;
49
48
}
50
49
}
51
50
52
- private void OutputSection < TModel > ( TagHelperOutput output , IHtmlHelper < TModel > helper , Section < TModel > s )
53
- {
54
- helper . ViewData [ "ChameleonFormSection" ] = s ;
55
- output . GetChildContentAsync ( ) . GetAwaiter ( ) . GetResult ( )
56
- . WriteTo ( helper . ViewContext . Writer , HtmlEncoder . Default ) ;
57
- ViewContext . ViewData . Remove ( "ChameleonFormSection" ) ;
58
- }
59
-
60
51
static Expression GetPropertySelector ( Type modelType , string propertyName )
61
52
{
62
53
var arg = Expression . Parameter ( modelType , "x" ) ;
0 commit comments