【发布时间】:2014-04-12 11:59:50
【问题描述】:
我的应用程序中有几个共享的 razor 部分视图,用于在不同页面上显示产品的一些详细信息。现在我需要根据呈现部分视图的主视图来更改部分视图内的一些链接。
例如:
如果部分视图在“index.cshtml”中呈现,则部分视图中的链接之一应该是:
<a href="www.site1.com">site1 called from index.cshtml</a>
如果它在“insert.cshtml”中,那么链接需要是
<a href="www.someothersite2.com">other site that's not 1 and it's called from insert.cshtml</a>
类似:
@if (something.parentview = "index.cshtml")
{ <a href="www.site1.com">site1 called from index.cshtml</a>}
else {
<a href="www.someothersite2.com">other site that's not 1 and it's called from insert.cshtml</a>
}
有没有办法做到这一点?
【问题讨论】:
-
您可以使用
ViewBag。在每个控制器中设置值并在局部视图中使用它们。 -
这是一个不好的例子,我现在改变了它......我的问题与控制器没有任何关系,我只需要在一两行中显示不同的数据,具体取决于共享部分呈现的位置...
标签: asp.net-mvc razor partial-views