@@ -43,30 +43,39 @@ public static string CurrencySymbol
4343
4444#if NET45
4545 public static MvcHtmlString Griddly ( this HtmlHelper htmlHelper , string actionName )
46+ {
47+ return htmlHelper . Griddly ( actionName , null ) ;
48+ }
4649#else
4750 public static async Task < IHtmlContent > Griddly ( this IHtmlHelper htmlHelper , string actionName )
48- #endif
4951 {
5052 return await htmlHelper . Griddly ( actionName , null ) ;
5153 }
54+ #endif
5255
5356#if NET45
5457 public static MvcHtmlString Griddly ( this HtmlHelper htmlHelper , string actionName , object routeValues )
58+ {
59+ return htmlHelper . Griddly ( actionName , null , routeValues ) ;
60+ }
5561#else
5662 public static async Task < IHtmlContent > Griddly ( this IHtmlHelper htmlHelper , string actionName , object routeValues )
57- #endif
5863 {
5964 return await htmlHelper . Griddly ( actionName , null , routeValues ) ;
6065 }
66+ #endif
6167
6268#if NET45
6369 public static MvcHtmlString Griddly ( this HtmlHelper htmlHelper , string actionName , string controllerName )
70+ {
71+ return htmlHelper . Griddly ( actionName , controllerName , null ) ;
72+ }
6473#else
6574 public static async Task < IHtmlContent > Griddly ( this IHtmlHelper htmlHelper , string actionName , string controllerName )
66- #endif
6775 {
6876 return await htmlHelper . Griddly ( actionName , controllerName , null ) ;
6977 }
78+ #endif
7079
7180#if NET45
7281 public static MvcHtmlString Griddly ( this HtmlHelper htmlHelper , string actionName , string controllerName , object routeValues )
@@ -274,16 +283,20 @@ public static void SetGriddlyDefault<T>(this Controller controller, ref T parame
274283
275284#if NET45
276285 if ( controller . ControllerContext . IsChildAction
286+ #else
287+ if ( controller . HttpContext . IsChildAction ( )
288+ #endif
277289 && ( ! context . IsDefaultSkipped || ignoreSkipped . Value )
278- && EqualityComparer < T > . Default . Equals ( parameter , default ( T ) ) )
290+ && ( EqualityComparer < T > . Default . Equals ( parameter , default ( T ) )
291+ #if ! NET45
292+ || typeof ( T ) . IsArray && ( parameter as Array ) ? . Length == 0 //In .NET core, the default value for array is null, but MVC binds the parameter as zero length array
293+ #endif
294+ ) )
279295 {
280296 parameter = value;
281297
282298 context. Parameters [ field ] = parameter ;
283299 }
284- #else
285- //TODO: implement
286- #endif
287300 }
288301
289302#if NET45
@@ -301,16 +314,16 @@ public static void SetGriddlyDefault<T>(this Controller controller, ref T[] para
301314
302315#if NET45
303316 if ( controller . ControllerContext . IsChildAction
317+ #else
318+ if ( controller . HttpContext . IsChildAction ( )
319+ #endif
304320 && ( ! context . IsDefaultSkipped || ignoreSkipped . Value )
305321 && parameter == null )
306322 {
307323 parameter = value . ToArray ( ) ;
308324
309325 context . Parameters [ field] = parameter ;
310326 }
311- #else
312- //TODO: implement
313- #endif
314327 }
315328
316329#if NET45
@@ -329,19 +342,18 @@ public static void SetGriddlyDefault<T>(this Controller controller, ref T?[] par
329342
330343#if NET45
331344 if ( controller . ControllerContext . IsChildAction
345+ #else
346+ if ( controller . HttpContext . IsChildAction ( )
347+ #endif
332348 && ( ! context . IsDefaultSkipped || ignoreSkipped . Value )
333349 && parameter == null )
334350 {
335351 parameter = value . Cast < T ? > ( ) . ToArray( ) ;
336352
337353 context . Parameters [ field ] = parameter ;
338354 }
339- #else
340- //TODO: implement
341- #endif
342355 }
343356
344- #if NET45
345357 public static void SetGriddlyDefault < TController, TModel , TProp > ( this TController controller , TModel model ,
346358 Expression < Func < TModel , TProp > > expression , TProp defaultValue , bool ? ignoreSkipped = null )
347359 where TController : Controller
@@ -351,13 +363,21 @@ public static void SetGriddlyDefault<TController, TModel, TProp>(this TControlle
351363
352364 var context = controller . GetOrCreateGriddlyContext ( ) ;
353365
366+ #if NET45
354367 var field = ExpressionHelper . GetExpressionText ( expression ) ;
368+ #else
369+ var field = ExpressionHelper . GetExpressionText ( expression , controller . HttpContext ) ;
370+ #endif
355371 context . Defaults [ field] = defaultValue ;
356372
357373 var compiledExpression = expression . Compile ( ) ;
358374 TProp parameter = compiledExpression ( model ) ;
359375
376+ #if NET45
360377 if ( controller . ControllerContext . IsChildAction
378+ #else
379+ if ( controller . HttpContext . IsChildAction ( )
380+ #endif
361381 && ( ! context . IsDefaultSkipped || ignoreSkipped . Value )
362382 && EqualityComparer < TProp > . Default . Equals ( parameter , default ( TProp ) ) )
363383 {
@@ -376,9 +396,6 @@ public static void SetGriddlyDefault<TController, TModel, TProp>(this TControlle
376396 }
377397 }
378398 }
379- #else
380- //TODO: implement
381- #endif
382399
383400#if NET45
384401 public static object GetGriddlyDefault( this WebViewPage page , string field )
@@ -454,9 +471,12 @@ public static Dictionary<string, object> GetGriddlyDefaults(this RazorPageBase p
454471 }
455472
456473#if ! NET45
457- public static GriddlyContext GetOrCreateGriddlyContext ( this ActionContext context )
474+ public static GriddlyContext GetOrCreateGriddlyContext( this ActionContext actionContext )
458475 {
459- return GetOrCreateGriddlyContext ( context . RouteData , context . HttpContext ) ;
476+ var context = GetOrCreateGriddlyContext ( actionContext . RouteData , actionContext . HttpContext ) ;
477+ if ( actionContext is ViewContext vc)
478+ vc. ViewData[ _contextKey] = context;
479+ return context;
460480 }
461481
462482 public static GriddlyContext GetOrCreateGriddlyContext( this Controller controller)
@@ -472,8 +492,8 @@ public static GriddlyContext GetOrCreateGriddlyContext(this ControllerBase contr
472492#else
473493 private static GriddlyContext GetOrCreateGriddlyContext( RouteData routeData , HttpContext httpContext )
474494 {
475- var key = _contextKey + "_" + ( routeData . Values [ "controller" ] as string ) . ToLower ( ) + "_" + ( routeData . Values [ "action" ] as string ) . ToLower ( ) ;
476- var context = httpContext . Items [ key ] as GriddlyContext ;
495+ // var key = _contextKey + "_" + (routeData.Values["controller"] as string).ToLower() + "_" + (routeData.Values["action"] as string).ToLower();
496+ var context = httpContext. Items[ _contextKey ] as GriddlyContext;
477497#endif
478498
479499 if ( context = = null )
@@ -523,7 +543,7 @@ private static GriddlyContext GetOrCreateGriddlyContext(RouteData routeData, Htt
523543#if NET45
524544 controller. ViewData [ _contextKey ] = context ;
525545#else
526- httpContext . Items [ key ] = context ; //TODO: Review
546+ httpContext . Items [ _contextKey ] = context ;
527547#endif
528548 }
529549
0 commit comments