1

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?

2 Answers 2

6

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?

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.