ViewData未保留在网格局部视图中

时间:2015-12-18 12:42:50

标签: asp.net-mvc grid partial-views umbraco7 tempdata

我有一个自定义网格视图,它使用renderRow helper类似于Urvish post 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

我试图通过使用TempData将网格设置传递给网格部分面板,但TempData对我的PartialViewMacroPageExtensions类和宏部分视图本身都是空的。

        @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();
    }
}

有没有办法将网格元素设置传递给它的局部视图?

1 个答案:

答案 0 :(得分:0)

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

TempData.Keep(“TempDataName”);