How to add css/script only to a Partial view?

后端 未结 3 2094
挽巷
挽巷 2021-01-06 12:40

I need to load css and scripts only to a specific Partial view but at this moment this link and scripts are loaded in all views. The structure that I have is the main view e

3条回答
  •  失恋的感觉
    2021-01-06 13:21

    You cannot load CSS and JavaScript resources specifically for a partial view without it applying to the entire page. Therefore, you'll need to design your page styles or JavaScript to target only the relevant sections.

    ...

    If I wanted to style the ul.menu differently, I'd use selector rules

    JavaScript

    $("#header-section > .menu").css({ ... });
    $("#search-header > .menu").css({ ... });
    

    Or in a CSS file

    #header-section > .menu { ... }
    #search-header > .menu { ... }
    

    Or just use distinct classes or specific ids

    .header-only { font-size: 1em; } .search-header-only { font-size: 0.85em; } #special-item { font-size: 1.5em; }

提交回复
热议问题