在渲染时动态选择 Spark Master 布局
每次发出页面请求时,我都需要选择 Spark Master 布局。我尝试通过在 OnActionExecuting 中设置 ViewBag.Layout 值并在主布局引用中引用该值来实现此目的。
<use master="${ViewBag.Layout}"/>
但是,这不起作用,似乎 Spark 没有将括号内的代码视为代码,而是视为字符串。我收到以下错误:
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Home/Index.cshtml
~/Views/Home/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
Layouts\${ViewBag.Layout}.spark
Shared\${ViewBag.Layout}.spark
任何人都可以告诉我这是为什么吗?或者指出我有另一种方法可以做到这一点?
I need to choose my spark master layout every time a request for a page is made. I attempted to so this by setting a ViewBag.Layout
value in OnActionExecuting
and referencing this value in the master layout ref.
<use master="${ViewBag.Layout}"/>
However, this doesn't work, it seems as if spark is not treating the code within the brackets not as code, but as a string. I get the following error:
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Home/Index.cshtml
~/Views/Home/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
Layouts\${ViewBag.Layout}.spark
Shared\${ViewBag.Layout}.spark
Can anyone tell me why this is? Or point me to an alternative way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无法使用代码语法动态选择布局。其原因是该布局是在引擎中进行任何渲染之前选择的。因此,首先定位布局,然后引擎尝试将所有变量渲染到位。对布局使用变量意味着渲染引擎不知道要打开哪个文件。
The layout cannot be dynamically selected using code syntax. The reason for this is that that layout is selected prior to any rendering taking place in the engine. So first the layout is located, and then the engine tries to render all the variables in place. Using a variable for the layout means that the rendering engine doesn't know which file to open.
实际上。这是可能的..而不是使用代码示例。使用结果过滤器。
Actually. it is possible.. Instead of using the code example. Use a ResultFilter.