Unable to generate a custom path in ASP.NET MVC Master Pages - asp.net-mvc

I am working in an ASP.NET MasterPage and am having trouble with <link href="..." />.
I am trying to substitute in a stylesheet with a specific name:
<link href="/Content/Styles/<%=Model.Style%>.css" rel="stylesheet" type="text/css" />
Unfortunately, this creates the HTML output:
<link href="/Content/Styles/<%=Model.Style%>.css" rel="stylesheet" type="text/css" />
Which is clearly not what was intended.
If I put the same code in a View placeholder, it works perfectly. This is not a good solution though as I have many pages where I just want it to do the same thing.
It looks like it's trying to automatically correct the URL - is there a way to switch this off?
Edit 1:
I have fixed this temporarily using:
<link href=<%=String.Format("\"/Content/Styles/{0}.css\"", Model.Style)%> rel="stylesheet" type="text/css" />

All the links in your question and in the solution posted thus far will fail if your site is deployed in a virtual folder. Instead, do:
<link href="<%= Url.Content("~/Content/Styles/" + Model.Style + ".css") %>" rel="stylesheet" type="text/css" />
This (1) fixes the problem in your question, and (2) allows your site to work in a virtual folder.

Try this:
<link href="/Content/Styles/<%= "" + Model.Style%>.css" rel="stylesheet" type="text/css" media="screen" />
Ugly but works.

Related

Thymeleaf's <th> not working at runtime

I am trying to run this links with thymeleaf but it doesnt work
, the static version with th: runs fine but when using jetty and trying to get thesame css files at run time it does not work
<link rel="stylesheet"
href="../../resources/static/css/font-awesome.min.css"
th:href="#{/resources/static/css/font-awesome.min.css}">
<link rel="stylesheet"
href="../../resources/static/css/bootstrap.css"
th:href="#{/resources/static/css/bootstrap.css}">
If you're accessing your app from http://localhost:8080, try removing the absolute path.
See if this works:
<link rel="stylesheet"
th:href="#{/resources/static/css/font-awesome.min.css}"
href="/css/font-awesome.min.css" />
<link rel="stylesheet"
th:href="#{/resources/static/css/bootstrap.css}"
href="/css/bootstrap.css" />
Also, try to access you css on the browser URL to see if it shows its content:
http://localhost:8080/css/font-awesome.min.css
or
http://localhost:8080/css/bootstrap.css
Hope it's somehow useful.

Asset name gets replaced by a dot

I'm using Ruby on Rails and I'm facing a problem.
When i run my application on the server, I get the following:
<link rel="stylesheet" media="all" href="/assets/..self-f28d8f57a7f19b756969e1ff016e5d807dd2b40d26e0e65c1a849f82fa5bd4b8.css?body=1" data-turbolinks-track="true" />
<link rel="stylesheet" media="all" href="/assets/reset.self-6aa5650b7ba29c22295359e84be792256c2c0e09887497329e717eb441b2878c.css?body=1" data-turbolinks-track="true" />
<link rel="stylesheet" media="all" href="/assets/application.self-dae5c5da7223ce739ad497817a3df9ba2fa2840da302653b11558b4f7d98bfc3.css?body=1" data-turbolinks-track="true" />
application.css is the default CSS that compiles all the SASS into one file, then you have reset.css that's added manually by me, and finally you have ..self.css.
This is the problem. This file is supposed to be index.scss. (I know it, because when I delete and create it by myself it loads correctly.)
rails generate controller
In the SCSS and JS files generated by the method when running the server the name is replaced by a dot.
Can someone help?

How to add media type to stylesheet reference asp mvc

I'm using asp mvc, and I'm using the following code to generate the CSS html reference:
#Styles.Render("~/Content/css")
which generates the following html:
<link href="/Content/site.css" rel="stylesheet"/>
and that works fine. However, I need to add media type as an additional attribute. How can I go about using this style.render to add attributes to the generated html? Should I be thinking about making the change in the bundle config instead?
edit: I would like the end product to look like this:
<link href="/Content/site.css" rel="stylesheet" media="handheld"/>
You should be using #Styles.RenderFormat() for that:
#Styles.RenderFormat(#"<link href=""{0}""
rel=""stylesheet""
media=""handheld"" />",
"~/Content/css")
Try this
< link href="#Styles.Url("~/Content/css")" rel="stylesheet" type="text/css" media="handheld" />

Object doesn't support this property or method - jqGrid 4.4.0

I'm using jqGrid 4.4.0 in an mvc2 application. The grid loads with the data fine. However, when I edit/add or delete records I get an 'Object doesn't support this property or method' error. This is how my setup looks like on the site.master page:
<link rel="stylesheet" type="text/css" media="screen" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.16/themes/redmond/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="../../Content/ui.jqgrid.css" />
<script src="<s:url value= http://ajax.microsoft.com/ajax/jquery/jquery-1.7.min.js" type="text/jscript"></script>
<script src="../../Scripts/grid.locale-en.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.jqGrid.min.js" type="text/javascript"></script>
What am I missing?
okay, even i got this error many times...i worked it out with two solution...first try this one, if it doesn't work for you...then paste your exact code here, where u r getting that error.
you need to include this grid.inlinedit.js if you are doing inline edit and grid.formedit.js if you are doing form edit...let me know if this sloves your problem or not...if it doesn't i'll provide the second solution

how to link css file at html page

i have some script..it lies in some direktori :
var/www/html/dataTables-1.6/media/css/demo_page.css
how to put in html page?
<link href=......??? rel="stylesheet" type="text/css" media="all">
Assuming html is your webroot, place the following in your head tag.
<link href="/dataTables-1.6/media/css/demo_page.css" rel="stylesheet" type="text/css" media="all">
Is this what you were asking?
You could use the full server path "/location/of/the/file/here.css" or you could use the relative path from where the file you are placing it in resides. "../back/one/directory.css". Or you could use the full web URL for it "http://www.yourhost/yourwebRoot/yourfile.css".

Resources