views:

105

answers:

2

In my view, I have included the Master page as follows:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Mall.Master" Inherits="System.Web.Mvc.ViewPage<DomainModel.Entities.Seller>" %>

And in my Mall.master file, I add a link to include a general css file

      <link rel="Stylesheet" href="../../Content/MallMaster.css"  type="text/css" />

However, I need another more specific purpose css file CheckOut.css in my view. Since the style defined in Checkout.css only applies for one page, I do not want to include the file in the master page. Is there any way to include the file in my view?

+5  A: 

You should add a new content () placeholder in your MasterPage and then in your view you can add another css to this placeholder.

<asp:ContentPlaceHolder ID="head" runat="server"> <title></title> <link rel="Stylesheet" href="../../Content/MallMaster.css" type="text/css" /> </asp:ContentPlaceHolder>

This may be helpful for you - How to pass page’s meta tags in ASP.NET MVC?

Tadas
Thanks a lot. This works right away.
Wei Ma
+1  A: 

If you don't want to override existing tags in the master, you can add a content placeholder inside the head tag too:

<head runat="server">
    <title>
        <asp:ContentPlaceHolder ID="title" runat="server">
            Default Title</asp:ContentPlaceHolder>
    </title>
    <!-- The ContentPlaceHolder is placed inside the title tag to make sure that the
         document validates in the VS editor - <title> needs to be a direct child of
         <head>. The output will validate. -->

    <script src="theAllFamous_jQuery.js" type="text/javascript" />
    <link href="sitewide.css" type="text/css" rel="Stylesheet" />
    <asp:ContentPlaceHolder ID="headContent" runat="server />
</head>

And in your view:

<asp:Content ID="title" ContendPlaceHolderId="title" runat="server">
    Page specific title
</asp:Content>

<asp:Content ID="head" ContentPlaceHolderId="headContent" runat="server">
    <link href="pagespecific.css" type="text/css/ rel="Stylesheet" />
</asp:Content>

That way you won't have to duplicate code that you want in all head tags on your site.

Tomas Lycken