Pregunta

I encounter in some web app that some partial view that is used has head element (it loads some Jquery things).

The thing is that with that and the _layout.xml I get this wierd HTML page structure

    <head>
...
    </head>
    <body>
...
    </body>
    <head>
...
    </head>
    <body>
....
    </body>

doesn't feel right..

  1. What's the best practice to load some .css.js to particular page? is it all done by _layout.xml and bundles?

  2. and in general - only _layout.xml should contain head element? no other view in my solution?

¿Fue útil?

Solución

You want only one head. Use layout with sections and add MVC sections in normal pages to add CSS or JScript. See here on basic section usage http://weblogs.asp.net/scottgu/archive/2010/12/30/asp-net-mvc-3-layouts-and-sections-with-razor.aspx. If you want to use partial create a helper to render section from partial see this answer Using sections in Editor/Display templates

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top