Asp.Net MVC5网页 - 在_Navigation视图中使用@RenderSection

时间:2016-02-04 20:50:49

标签: asp.net-mvc razor asp.net-mvc-5

我有一个_Navigation.cshtml视图,我尝试使用Razor sf::Clock clock; // Initializing clock starts counting time. while(someCondition) { sf::Time time = clock.getElapsedTime(); //It's going to execute do something() until time is higher than 10.0f while(time.asSeconds() <= 10.0f) { //we need this to ensure that we won't fall into the infinite loop time = clock.getElapsedTime(); do something() //Optional: clock.restart(); If you want your code to be executed every x seconds. } } <ul> </ul>指令添加一些条件IsSectionDefined()标记。

但是,我收到以下异常:

@RenderSection()

正如您在下面的HTML代码段中所看到的,我可以非常轻松地将The file "~/Views/Shared/_Navigation.cshtml" cannot be requested directly because it calls the "RenderSection" method.添加到@RenderSection("bobtest")视图中,但不能在_Layout.cshtml视图中添加:

来自.. \ Views \ Home \ Index.cshtml的片段:

&#13;
&#13;
_Navigation
&#13;
&#13;
&#13;

这是我的_Layout.cshtml,它引入&#34; _Navigation&#34;,&#34; _TopNavbar&#34;和&#34; _Footer&#34;

&#13;
&#13;
@section bobtest{
    <ul class="nav nav-second-level collapse @Html.IsSelected(controller: "Dashboards", cssClass: "in")">
    <li class="@Html.IsSelected(action: "Dashboard_1")"><a href="@Url.Action("Dashboard_1", "Dashboards")">Dashboard v.1</a></li>
    <li class="@Html.IsSelected(action: "Dashboard_2")"><a href="@Url.Action("Dashboard_2", "Dashboards")">Dashboard v.2</a></li>
    <li class="@Html.IsSelected(action: "Dashboard_3")"><a href="@Url.Action("Dashboard_3", "Dashboards")">Dashboard v.3</a></li>
</ul>
&#13;
&#13;
&#13;

以下是<div id="wrapper"> <!-- Navigation --> @Html.Partial("_Navigation") <!-- Page wraper --> <div id="page-wrapper" class="gray-bg"> <!-- Top Navbar --> @Html.Partial("_TopNavbar") <!-- Main view --> @RenderBody() @RenderSection("bobtest", required: true) <!-- THIS WORKS... --> <!-- Footer --> @Html.Partial("_Footer") </div> <!-- End page wrapper--> </div>视图的摘要:

&#13;
&#13;
_Navigation
&#13;
&#13;
&#13;

这只会导致异常,所以我需要清楚一点如何将条件标签添加到我的_Navigation视图中。

感谢, 鲍勃

0 个答案:

没有答案