1
1
using Microsoft . AspNetCore . Html ;
2
+ using Microsoft . AspNetCore . Mvc ;
2
3
using Microsoft . AspNetCore . Mvc . Rendering ;
3
4
using Microsoft . AspNetCore . Mvc . ViewComponents ;
4
5
using Microsoft . AspNetCore . Mvc . ViewEngines ;
@@ -204,7 +205,8 @@ private string GetContentTypeAliasByGuid(Guid contentTypeGuid)
204
205
}
205
206
206
207
public IHtmlContent RenderDocTypeGridEditorItem (
207
- IHtmlHelper helper ,
208
+ IViewComponentHelper helper ,
209
+ IHtmlHelper htmlHelper ,
208
210
dynamic model )
209
211
{
210
212
if ( model . value != null )
@@ -216,38 +218,40 @@ public IHtmlContent RenderDocTypeGridEditorItem(
216
218
string viewPath = model . editor . config . viewPath . ToString ( ) ;
217
219
218
220
var content = ConvertValue ( id , contentTypeAlias , value ) ;
219
- return RenderDocTypeGridEditorItem ( helper , content , editorAlias , viewPath ) ;
221
+ return RenderDocTypeGridEditorItem ( helper , htmlHelper , content , editorAlias , viewPath ) ;
220
222
}
221
223
222
224
return null ;
223
225
}
224
226
225
227
public IHtmlContent RenderDocTypeGridEditorItem (
226
- IHtmlHelper helper ,
228
+ IViewComponentHelper helper ,
229
+ IHtmlHelper htmlHelper ,
227
230
IPublishedElement content ,
228
231
string editorAlias = "" ,
229
232
string viewPath = "" ,
230
233
string previewViewPath = "" ,
231
234
bool isPreview = false )
232
235
{
233
236
if ( content == null )
234
- return new HtmlString ( string . Empty ) ;
237
+ return new HtmlString ( "<pre>content is null</pre>" ) ;
235
238
236
239
// get view path
237
- if ( ! TryGetViewPath ( helper . ViewContext , editorAlias , content . ContentType . Alias , viewPath , previewViewPath , isPreview , out string fullViewPath ) )
240
+ if ( ! TryGetViewPath ( htmlHelper . ViewContext , editorAlias , content . ContentType . Alias , viewPath , previewViewPath , isPreview , out string fullViewPath ) )
238
241
{
239
- return new HtmlString ( string . Empty ) ;
242
+ return new HtmlString ( $ "<pre>could not get viewpath. { editorAlias } , { content . ContentType . Alias } , { viewPath } , { previewViewPath } , { isPreview } , { fullViewPath } </pre>" ) ;
240
243
}
241
244
242
- var renderParams = new object [ ] { content , fullViewPath } ;
245
+ var renderParams = new { model = content , viewPath = fullViewPath } ;
243
246
var viewComponent = _options . DefaultDocTypeGridEditorViewComponent ;
244
247
245
- if ( TryGetComponent ( editorAlias , out ViewComponentDescriptor component ) || TryGetComponent ( content . ContentType . Alias , out component ) )
248
+ if ( ! TryGetComponentName ( new [ ] { editorAlias , content . ContentType . Alias } , out string componentName ) )
246
249
{
247
- viewComponent = component . GetType ( ) ;
250
+ return new HtmlString ( $ "<pre>could not get componentName. { editorAlias } , { content . ContentType . Alias } , { componentName } </pre>") ;
251
+
248
252
}
249
253
250
- return helper . RenderComponentAsync ( viewComponent , RenderMode . Static , renderParams ) . Result ;
254
+ return helper . InvokeAsync ( componentName , renderParams ) . Result ;
251
255
}
252
256
253
257
private bool TryGetViewPath ( ViewContext viewContext , string editorAlias , string contentTypeAlias , string viewPath , string previewViewPath , bool isPreview , out string fullViewPath )
@@ -292,13 +296,19 @@ private bool TryGetViewPath(ViewContext viewContext, string editorAlias, string
292
296
return ! fullViewPath . IsNullOrWhiteSpace ( ) ;
293
297
}
294
298
295
- private bool TryGetComponent ( string name , out ViewComponentDescriptor component )
299
+ private bool TryGetComponentName ( string [ ] names , out string componentName )
296
300
{
297
- component = null ;
298
- if ( name . IsNullOrWhiteSpace ( ) ) return false ;
299
-
300
- component = _viewComponentSelector . SelectComponent ( $ "{ name } DocTypeGridEditorViewComponent") ;
301
- return component != null ;
301
+ componentName = "" ;
302
+ foreach ( var name in names )
303
+ {
304
+ Console . WriteLine ( $ "getting component name for { name } ") ;
305
+ if ( _viewComponentSelector . SelectComponent ( $ "{ name } DocTypeGridEditor") != null )
306
+ {
307
+ componentName = $ "{ name } DocTypeGridEditor";
308
+ return true ;
309
+ }
310
+ }
311
+ return false ;
302
312
}
303
313
304
314
public static bool ViewExists ( ViewContext viewContext , string viewName )
0 commit comments