Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3843014
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:52:38+00:00 2026-05-19T15:52:38+00:00

I wanna switch the css that is being applied to my mvc app. I

  • 0

I wanna switch the css that is being applied to my mvc app. I want to do this in my Index page. The defenition for the default css is in the site.master defined like this:

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

The jquery I am trying to use which may or may not be right is

 $(document).ready(function() { 
        $("link").attr("href", '../../Content/nick.css');

    });
});

I wanna somehow put this jquery in the Index page (which is the basic Index view that loads with MVC)

>   <%@ Page Language="C#"
> MasterPageFile="~/Views/Shared/Site.Master"
> Inherits="System.Web.Mvc.ViewPage" %>
> 
> <asp:Content ID="Content1"
> ContentPlaceHolderID="TitleContent"
> runat="server">
>     Home Page
>     </asp:Content>
>     <asp:Content ID="Content2" ContentPlaceHolderID="MainContent"
> runat="server">
>         <h2><%: ViewData["Message"] %></h2>
>         <p>
>             To learn more about ASP.NET MVC visit <a
> href="http://asp.net/mvc"
> title="ASP.NET MVC
> Website">http://asp.net/mvc</a>.
>         </p>
>     </asp:Content>

Can someone look at my jquery and see if its right and show my how I can hook this up? Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T15:52:38+00:00Added an answer on May 19, 2026 at 3:52 pm

    I believe your jQuery should be changed to:

    $(function() {
        $('link').first().attr('href', 'nick.css');
    });
    

    Assuming that it is the first css file you want to change. There’s nothing wrong with using an ID property for the link tag though:

    <link id="style" href="../../Content/Site.css" rel="stylesheet" type"text/css" />
    

    And then your jQuery can be:

    $('link#style').attr('href', 'nick.css');
    

    You can put the jQuery anywhere you want in your index page, as long as you wrap it in a <script> tag, but what I recommend you do is to add a ContentPlaceHolder in the <head> tag of your Master page:

    <head>
        <title><asp:ContentPlaceHolder ID="TitleHolder" runat="server"></title>
        <asp:ContentPlaceHolder ID="ScriptContent" runat="server" />
    </head>
    

    Then in your index page, add a section for it:

    <asp:Content ContentPlaceHolderID="ScriptContent" runat="server">
        <script>
            $(function() {
                $('link#style').attr('href', 'nick.css');
            });
        </script>
    </asp:Content>
    

    Adding Model data to jQuery

    It’s pretty much the same thing you would do in HTML:

    <script>
        $(function() {
            $('link#style').attr('href', <%= Model.CssStyle %>);
        });
    

    This is assuming your Model has a property called CssStyle. You might get warnings when you compile the program about invalid Javascript tags but you can safely ignore them. Javascript support within Visual Studio is not that great without plugins.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanna know that how we can identify whether a page is redirecting to
In my app, I wanna use both location provider. That means, if the gps
I wanna switch the styles the datascroller uses to shows the selected page. Is
I wanna show a picture inside the default value of a text field. this
I wanna create an app that will have three view controllers. To navigate between
i wanna add a service behavior(or anything u'll suggest) that will automatically insert the
I wanna verify a digitally signed xml against its schema definition while this schema
I wanna develop an addon (basically a hack) for IPhone native phone app. My
I wanna implement a javascript like method in java , is this possible ?
I wanna have a drop down that lets me select Week Commencing Monday the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.