0

I have a custom grid view which uses renderRow helper similarily to Urvish post here https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/64536-How-to-use-grids-with-views-and-maybe-controls-to-make-it-look-good

I'm trying to pass grid settings to grid partial panels by using TempData but the TempData is getting null both to my PartialViewMacroPageExtensions class and the macro partial view itself.

        @foreach (var control in area.controls) {
            if (control != null && control.editor != null && control.editor.view != null) {
                TempData["grid-settings"] = area.config;
               <text>@Html.Partial("grid/editors/base", (object)control)</text>
            }
        }


public static class PartialViewMacroPageExtensions
{
    public static T GetGridProperties<T>(this PartialViewMacroPage page)
        where T : new()
    {
        if (page.TempData["grid-settings"] != null)
        {
            return JsonConvert.DeserializeObject<T>(page.TempData["grid-settings"].ToString());
        }

        return new T();
    }
}

Is there any way to pass grid element settings to it's partial view?

nickornotto
  • 1,946
  • 4
  • 36
  • 68
  • The problem you are having is as soon as you check if `TempData` is null you instantly read it and it get's removed from `TempData`. Where you are preforming your null checks do this `TempData.Peek("grid-settings")` – Jamie Rees Dec 18 '15 at 14:37
  • Nope, still null @Jamie – nickornotto Dec 18 '15 at 14:47
  • How many HTTP requests are being preformed? the `TempData` only lasts for 1 request – Jamie Rees Dec 18 '15 at 14:51
  • Yes, I know, I'm trying to check requests with Fiddler and it's actually showing only 1 request for the current page although multiple other requests for css, scripts, images etc so I guess they don't count? @Jamie – nickornotto Dec 23 '15 at 11:39

1 Answers1

0
Please use this code for keep tempdata value  where you stored TempData.

TempData.Keep(“TempDataName”);
Dilip Oganiya
  • 1,504
  • 12
  • 20