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
I believe your jQuery should be changed to:
Assuming that it is the first css file you want to change. There’s nothing wrong with using an ID property for the
linktag though:And then your jQuery can be:
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 aContentPlaceHolderin the<head>tag of your Master page:Then in your index page, add a section for it:
Adding Model data to jQuery
It’s pretty much the same thing you would do in HTML:
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.