yad4u ASP.NET MVC - Do stylesheets have to go in the Site.Master file?


ASP.NET MVC - Do stylesheets have to go in the Site.Master file?



I noticed that I cannot add stylesheets on any page. They must be added to the master page.

I already have about 15 stylesheets in the master view, which seems like overkill, since only some of the pages use a certain stylesheet.

I imagine I could reference the file via javascript (although, I can't think of how off the top of my head), but it would be really nice to not have to use any.


Use of IsAssignableFrom and “is” keyword in C#

1:

what would be the best method to override the validation of data in an mvc application
You should be able to add them to the head placeholder on the content pages.... Issue with jquery #find on partial postback MasterPage:. Weird stack trace in exception “The incoming request does not match any route”
<head>    <asp:ContentPlaceHolder ID="HeadContent" runat="server" /> </head> 
Content Page:. How to read system.web section from web.config
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">     <%-- link styles here...--%> </asp:Content> 
Validate checkboxes in MVC formASP.NET MVC 2 - Checkboxes

2:

displaying a listbox using Html.List, and I have a List<User> collection
No, they don't have to go in the master page.. You must create a content placeholder for them in the master page, and then add page-specific styles using a content element on the page.. E.g., in the master:.
<head>     <asp:ContentPlaceHolder ID="Styles" runat="server">     </asp:ContentPlaceHolder> </head> 
Then in the page:.
<asp:Content ID="styleContent" ContentPlaceHolderID="Styles" runat="server">     <link rel="stylesheet" type="text/css" href="<%= Url.Content("~/Content/style/MyStyles.css") %>" /> </asp:Content> 

3:

Can you show any code? . It's actually possible to have a CSS stylesheet in the view. But the question is if it's a good practice. The best idea is to create a placeholder in the masterpage in the Head section and use this placeholder in the view to use the correct CSS files. . Like this:. In your masterpage:.
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title>Example</title>     <asp:ContentPlaceHolder ID="HeadContent" runat="server" /> </head>  <body> 
Inside your view:.
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">     <link href="<%= Url.Content("~/Content/style/MyStyles.css") %>" rel="stylesheet" type="text/css" /> </asp:Content> 

4:

You must store stylesheets, along with images and control skins, as part of a Theme and specify on each content page which theme should be used. Note: You must not specify a theme in the MasterPage itself. It only works with Page directives.. Note this this requires the head element to be runat="server" to have ASP.NET automagically add the appropriate stylesheet references to the page.. I'm not sure if this applies to ASP.NET MVC or not, although you are using a MasterPage....


89 out of 100 based on 64 user ratings 959 reviews