0

I use the following bundle to load css and it works :

bundles.Add(new StyleBundle("~/bundles/jqGrid-styles").Include(
                "~/Content/themes/base/jquery-ui.css",
                "~/Content/jquery.jqGrid/ui.jqgrid.css"));

...

In my layout page this works :

@Styles.Render("~/bundles/jqGrid-styles")

And if i try simply adding the links to page it doesn't work .

This doesn't work at all:

<link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" />
<link href="~/Content/jquery.jqGrid/ui.jqgrid.css" rel="stylesheet" />

Can someone explain my why by simply adding the links to the page this doesn't work ? The files are there in the correct location.

6
  • Can you add the HTML produced from the <link> elements, and tell if these stylesheets are requested from the server, and what's the result? Commented Nov 25, 2014 at 9:15
  • i think dot in file names may create problem instead of . use - Commented Nov 25, 2014 at 9:18
  • the html is : <link rel="stylesheet" href="/Content/themes/base/jquery-ui.css" ></link> <link rel="stylesheet" href="/Content/jquery.jqGrid/ui.jqgrid.css" ></link> Commented Nov 25, 2014 at 9:19
  • the page inspector says its never used Commented Nov 25, 2014 at 9:24
  • @Kartikeya dots shouldn't be a problem Commented Nov 25, 2014 at 9:34

2 Answers 2

1

You need to add Url.Content method:-

<link href="@Url.Content("~/Content/themes/base/jquery-ui.css") rel="stylesheet" />
<link href="@Url.Content("~/Content/jquery.jqGrid/ui.jqgrid.css") rel="stylesheet" />

You need to pick the files from applications absolute path.

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

8 Comments

you are wrong. MVC is part of ASP.NET, and can definitely interpret URLs like in the question and replace the tilde with the base URL. We do it ourselves with no problems. And you need to add an opening quote mark inside your Url.Content call.
@TsahiAsher - Thanks for pointing, Corrected! Also, as pointed by OP the resulting href is href="/Content/themes/base/jquery-ui.css" which in my view is wrong.
What's wrong with it? If his site is in the root of the domain, it's perfectly OK.
it is adviced to use @Url.Content() helper while working in mvc but i don't think this will solve OP's problem...
@TsahiAsher - Its working for you because probably you are running your app locally, check this probelm with ASP.NET MVC well explained here:-blogs.msdn.com/b/rickandy/archive/2011/04/22/…
|
0

Try this approach, it is basic html:

<link rel="stylesheet" href="~/Content/themes/base/jquery-ui.css" ></link>
<link rel="stylesheet" href="~/Content/jquery.jqGrid/ui.jqgrid.css" ></link>

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.