在某些视图中隐藏“渲染"页面 [英] Hide Render page in some views Razor

查看:61
本文介绍了在某些视图中隐藏“渲染"页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的mvc应用程序中,我已经建立了一个页脚并像这样嵌入

In my mvc app I a have made one footer and embedded it like this

<div class="off-canvas-wrap" data-offcanvas>
    <div class="inner-wrap">
         @Html.Action("Menu", "Site")
        <aside class="main-section">
            @RenderBody()
        </aside>
        @RenderPage("~/Views/Shared/DisplayTemplates/_footer.cshtml")
    </div>
</div>

此代码位于我的_layout.cshtml文件中,我试图在此处执行的操作是在特定页面上隐藏页脚.甚至可以在特定页面上隐藏页脚吗?

This code lies in my _layout.cshtml file, what I am trying to do here is to hide the footer on a certain page. Is it even possible to hide the footer on a particular page?

期待提出建议.

推荐答案

由于您的条件将在要呈现的页面中,而不是在布局中,因此您将必须保留一些全局函数,可以在页面加载后调用该函数.

Since your condition will be in the page being rendered and not the layout you will either have to keep some global function which can be called after the page is loaded. Something like

window.myfunction =function() {
    if (myConditionInJavaScript) {
        $("#myfooter").hide();
    }
}

,然后在您的子页面中调用此函数.通过 window.myfunction();

and call this function in your child page. by window.myfunction();

还可以使用Viewbag,但是在渲染或更新每个视图时,需要在每个视图中设置ViewBag的值.

Also you can use Viewbag but you need to set the value of the ViewBag in each view when it is being rendered or updated.

如果您只需要隐藏一个部分,对我来说,最有效的方法是保持两个单独的布局.因为无论您在每次页面加载时选择哪种方式,都会触发该条件,这可能会导致性能下降.

这篇关于在某些视图中隐藏“渲染"页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆