Skip to content

Grid identifier #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions Griddly.Mvc/GriddlyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,23 @@ private static GriddlyContext GetOrCreateGriddlyContext(RouteData routeData, Htt

sortFields = GriddlyResult.GetSortFields(items);

#if NETFRAMEWORK
string cookieSuffix = (controller.ControllerContext.RouteData.Values["gid"] as string);
#else
string cookieSuffix = (routeData.Values["gid"] as string);
#endif

if (string.IsNullOrEmpty(cookieSuffix))
cookieSuffix = items["gid"];

cookieSuffix = !string.IsNullOrEmpty(cookieSuffix) ? "_" + cookieSuffix.ToLower() : string.Empty;

context = new GriddlyContext()
{
#if NETFRAMEWORK
Name = (controller.GetType().Name + "_" + controller.ControllerContext.RouteData.Values["action"] as string).ToLower(),
Name = (controller.GetType().Name + "_" + controller.ControllerContext.RouteData.Values["action"] as string).ToLower() + cookieSuffix,
#else
Name = (routeData.Values["controller"] as string).ToLower() + "_" + (routeData.Values["action"] as string).ToLower(),
Name = (routeData.Values["controller"] as string).ToLower() + "_" + (routeData.Values["action"] as string).ToLower() + cookieSuffix,
#endif
PageNumber = pageNumber,
PageSize = pageSize,
Expand Down Expand Up @@ -622,7 +633,7 @@ public static string Current(this IUrlHelper helper, ViewContext vc, object rout
{
if (arrayVals.Length > 0)
arrayVals.Append("&");
arrayVals.Append(string.Join("&", ((IEnumerable)value.Value).Cast<object>().Select(x=> value.Key + "=" + x?.ToString())));
arrayVals.Append(string.Join("&", ((IEnumerable)value.Value).Cast<object>().Select(x => value.Key + "=" + x?.ToString())));
}
}
}
Expand Down Expand Up @@ -656,7 +667,7 @@ public static string Current(this IUrlHelper helper, ViewContext vc, object rout
}

var route = helper.RouteUrl(values);
if(arrayVals.Length>0)
if (arrayVals.Length > 0)
{
route += (route.Contains("?") ? "&" : "?") + arrayVals.ToString();
}
Expand Down
10 changes: 7 additions & 3 deletions Griddly.NetCore/Views/Home/MultipleDefaultTest.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
<div class="col-md-12">
<h2>Multiple Default Test</h2>
<h3>Grid 1</h3>
@await Html.GriddlyAsync("Test1Grid")
<h3>Grid 2</h3>
@await Html.GriddlyAsync("Test2Grid")
@await Html.GriddlyAsync("Test1Grid", new { gid = "Original" })
<h3>Copy Grid 1</h3>
@await Html.GriddlyAsync("Test1Grid", new { gid = "Copy" })
<h3>Original Grid 2</h3>
@await Html.GriddlyAsync("Test2Grid", new { gid = "Original" })
<h3>Copy Grid 2</h3>
@await Html.GriddlyAsync("Test2Grid", new { gid = "Copy" })
</div>
</div>
10 changes: 7 additions & 3 deletions Griddly/Views/Home/MultipleDefaultTest.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
<div class="col-md-12">
<h2>Multiple Default Test</h2>
<h3>Grid 1</h3>
@Html.Griddly("Test1Grid")
<h3>Grid 2</h3>
@Html.Griddly("Test2Grid")
@Html.Griddly("Test1Grid", new { gid = "Original" })
<h3>Copy Grid 1</h3>
@Html.Griddly("Test1Grid", new { gid = "Copy" })
<h3>Original Grid 2</h3>
@Html.Griddly("Test2Grid", new { gid = "Original" })
<h3>Copy Grid 2</h3>
@Html.Griddly("Test2Grid", new { gid = "Copy" })
</div>
</div>