- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚刚花了 2 个小时试图弄清楚为什么当我将一个字符串放入我的 Surface Controller 中的 View.Bag/ViewData 时,当我尝试在 View 中取回该字符串时我得到 null。
最后,我通过将字符串放入 session 变量中解决了这个问题。
想知道为什么它不起作用,以及如何修复它。
提前致谢。
最佳答案
更新:您在发帖和重定向吗?当您刷新表单时,它会提示您重新发布吗?如果不是,那是因为您不小心遵循了表单发布的 302ing 最佳实践(防止用户刷新和重新发布表单数据)。我遵循的登录表面 Controller 的示例都使用了 return RedirectToCurrentUmbracoPage()
我盲目地遵循了。但是,顾名思义,真的是在做重定向,而且真的是两个请求! (我固执的要在Fiddler里验证才相信)。 ViewData 和 ViewBag 仅适用于一个请求——因此它们在 POST 302 中根本被破坏。 session 适用于多个请求,这就是它对您有用的原因。 TempData 也适用于您,因为事实证明,TempData 是一种构建在 session 之上的构造,专门设计用于在两个帖子之间传输状态(在检索时删除)。我在某处读到,将 TempData 命名为 RedirectData
会更好,这有助于我点击它。
因此,当您处理 Surface Controller 和 POST 时,您有三个我知道可行的选项:
return CurrentUmbracoPage();
。我刚刚在Fiddler中验证了这正是一个请求(在浏览器中刷新提示重新发布警告)。我还验证了 ViewData 以这种方式工作。但是,因为表面 Controller 是使用 @Html.Action(...)
呈现为子操作,所以您必须使用 ParentActionViewContext
来获取正确的 ViewData(我的第一个我会留给发现这个问题的其他人的答案)。当不涉及重定向(GET 或返回 CurrentUmbracoPage()
)的 POST 时,原始答案仍然有用...
在许多情况下,您实际上是在执行子操作。通常你只有一层深度,但如果你混合使用宏和部分,你实际上可以获得多层深度。每个级别都有一个 ViewData,您必须使用 ParentActionViewContext
在堆栈中向上走,才能到达您在 Controller 中填充的顶部 ViewData
。
参见 this comment from Shannon在回答有关表面 Controller 和 View 数据的问题时(Shannon 是 HQ 团队的核心贡献者,并且有很多很棒的内容)。此处引用:
If you want to access the ViewData that you've set on the master ViewContext's on a ChildAction being rendered from the master's ViewContext then you need to use @ViewContext.ParentActionViewContext.ViewData["ErrorMessage"]
The ParentActionViewContext in this example is the ViewContext that is rendering the Umbraco template, not the ChildAction. That is because when you POST (whether inside of Umbraco or normal MVC), you are posting to a new Action and the rendering process starts from scratch, when you validate your model, update the ViewData, etc... this all happens on what will become the 'master' ViewContext when the view renders. This view then will render your ChildAction.
关于umbraco - 如何将 ViewData 和 ViewBag 与 Umbraco 表面 Controller 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27990225/
我有以 xyz 点格式表示 3D 表面(即地震断层平面)的数据。我想创建这些表面的 3D 表示。我使用 rgl 和 akima 取得了一些成功,但是它无法真正处理可能会自行折叠或在同一 x,y 点具有
我正在尝试将此 X、Y、Z 数据集拟合到未知表面。 不幸的是,线性拟合不足以显示表面数据。我认为多项式拟合可能适合这种情况。另外,问题是我不知道如何建立多项式拟合函数来完成曲面拟合。 任何帮助都会很棒
我已经用plotly构建了一个表面图表,并且我正在尝试根据我自己的文本获得hoverinfo。奇怪的是它不再工作了。 library(plotly) x % layout(dragmode = "tu
我有以下数据: library(rgl) x y,y->z,z->x) zmat <- matrix(data = z, nrow = 6, ncol = 5, byrow = FALSE) surf
我正在使用 DXVA 视频解码器。它工作正常,但我想与另一个 IDirect3D9 设备对象共享解压缩的表面。 我读了this文件,我调用 IDirectXVideoDecoderService::C
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
import pygame, sys, os.path pygame.init() # set up the colours # R G B BLACK = ( 0,
我的目标是在 pygame 实例内显示一个颜色图,以 49 个元素 ndarray 的形式反射(reflect)实时输入,范围从 -6 到 2,标准化为 0 到 1 的值。到目前为止,我正在使用 ma
我在 Visual C# -> surface -> v2.0 -> MS visual C# 2010 express 中的 Surface Application (WPF) 模板中工作。 我正在
我正在尝试在 JavaFX 中实现我自己的 3D 表面动画,但我不理解它应该工作的一切,有人可以帮助我理解哪个应该放在哪里吗? 已经知道使用类构建Mesh需要类对象TraingleMesh然后必须使用
根据我的阅读,我不相信 SurfaceView 可以设置动画,但我会问这个问题: 我在 ViewFlipper 中有一个 surfaceView 对象。当 ViewFlipper 向左或向右移动到新的
我想在 android 屏幕上有一个图像,图像的不同部分可以点击。我的意思是,如果它是 3 个圆圈的图像,我希望能够单击这些圆圈中的每一个, 然后我可以为每个可点击的圆圈添加不同的功能。对于下图中的示
我有一个通过kinect获得的点集,现在我想创建一个网格。我正在尝试使用 CGAL 库并且正在关注 this example . 我使用的是 VS2010,它运行没有任何错误,但是当然它没有在行中
在让我的 SurfaceView 显示我的相机预览时遇到一点问题。我在这里查看了一些问题并通过 Google 搜索了一些 tuts,但我认为这可能是我这边的一个小错误,我只是没有看到。 代码 publ
任何人都可以为我指出一些类(class)或对以下情况提出任何建议吗? 我有一个 SurfaceView,它有一个背景图像,我希望在其上绘制其他位图。我想支持以下操作: 点击一下,新的位图就会添加到背景
我正在尝试学习表面 View 并且我确实读到了它。 所以,我试着制作了一个游戏,我认为它可以帮助我更好地学习。 我创建了一个表面 View 类,如下所示: class SnakeEngine exte
我希望笑脸 div(在用户进入墙壁后显示)将覆盖主迷宫表面而不改变笑脸大小:你能帮帮我吗? 这是 fiddle 链接: http://jsfiddle.net/uqcLn/66/ 这是笑脸 div:
我有一组 (x,y,z) 点,这些点具有相应的法线和值。所以数据的形式是 [x y z nx ny nz c]。我想在这些垂直于这些法线的点上绘制一个 3D 表面,并且具有与该值对应的颜色。所以我想要
我有一个不是函数图的表面的 3D 数据集。数据只是 3D 中的一堆点,我唯一能想到的就是在 Matlab 中尝试 scatter3。 Surf 将不起作用,因为表面不是函数图。 使用 scatter3
假设我有一个函数,例如: 现在,我想绘制它的曲面图(matplotlib plot_surface )。我使用 np.arange(stop,end,increment) 构造了三个数组。 在这里,我
我是一名优秀的程序员,十分优秀!