I'm using System.Web.Optimization.Bundle to bundle all my stylesheets. Is there a way to extend the Bundle Class to include custom attributes to get a following output?
<link href="/Content/Css/view.css" rel="stylesheet" data-class="en"/>
Here in the link element is the data-class="en" included:
bundles.Add(new CustomStyleBundle("~/bundles/css").Include("~/content/css/en/view.css"));
mvc4 bundle, how it is working?
Can be include it like this. No need to create a custom bundle.
<link href="#System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Content/css")" rel="stylesheet" type="text/css" />
Related
I'm new to web development but have some experience with C#, so I'm trying my luck with ASP.NET.
I was able to create the base app and so on, however now I want to use my own CSS stylesheet.
I tried using the exact syntax that the base app uses:
<head runat="server">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>#ViewData["Title"] - SmtteProject</title>
<environment include="Development">
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
</environment>
<environment exclude="Development">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute"
crossorigin="anonymous"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"/>
</environment>
<link rel="stylesheet" href="~/css/test.css"/>
<link rel="stylesheet" href="~/css/site.css" />
</head>
Where the test.css is the stylesheet I want to use. It is in the exact same directory as site.css, however I get this error in the console on the page:
GET http://localhost:5000/css/test.css net::ERR_ABORTED 404 (Not Found)
I tried using runat="server" in both the head and in the link, as I saw quite a few answers online with this solution. However, that did not do the trick either.
I tried displaying an image that was in an images directory in the exact same way, but encountered the same issue.
Any help welcome.
It's Cascading Style Sheets, or CSS. Not CCS. I think that this naming confusion is the root of your problem.
Your file is named test.ccs. It should be named test.css, per the HTML snippet you provided.
I just create a .net core 2.0 project on my visual studio and found in _Layout.cshtml few new properties like called- "environment". I worked on MVC5 but there was no such properties. What these propertie does? Is it replacement of Rezor Syntax which i used in MVC5 view? Please provide details with doc for use those properties to get started with those.
_Layout.cshtml:
<environment include="Development">
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="~/css/site.css" />
</environment>
<environment exclude="Development">
<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css"
asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
<link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
</environment>
We have 3 Environments; Development, Staging and Production.
This tag helper help us to render what we need in different environments.
the code below means that, if we are in DEVELOPMENT environment, render this css files.
<environment include="Development">
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="~/css/site.css" />
</environment>
and the code below means that render the content when we are NOT in DEVELOPMENT environment.
<environment exclude="Development">
<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css"
asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
<link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
</environment>
*note: asp-fallback-href in code above means if can't connect to cdn, go and use minified bootstrap file from server!
also you can write code above like this:
<environment include="Staging, Production">
<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css"
asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
<link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
</environment>
that means render the content if we are in STAGING or PRODUCTION environments.
The environment tag helper uses the value of IHostingEnvironment.EnvironmentName to include/exclude content in the DOM (Document Object Model) based on the current application environment.
In your snippet, the first two style sheets are included when running your code in a development environment, and the bottom two are excluded when in development environment.
See Microsoft docs on Tag Helper in ASP.NET Core and Environment Tag Helper , which could help more clearly to answer your question.
The Environment Tag Helper conditionally renders its enclosed content based on the current hosting environment.
The include attribute basically means render the code whether you're in Development environment, while it won't be rendered with exclude attribute.
I was trying to add kendo Map, i added necessary css and script files but i am not getting #(Html.Kendo().Map() i am getting all other widgets like splitter ,slider ,grid but no Map.
What would be the reason any guess?
Added files and dll shown below
<link href="~/Content/kendo.common.min.css" rel="stylesheet" />
<link href="~/Content/kendo.default.min.css" rel="stylesheet" />
<link href="~/Content/kendo.dataviz.default.min.css" rel="stylesheet" />
<link href="~/Content/kendo.default.min.css" rel="stylesheet" />
<script src="~/Scripts/jquery.min.js"></script>
<script src="~/Scripts/kendo.all.min.js"></script>
<script src="~/Scripts/kendo.aspnetmvc.min.js"></script>
#using Kendo.Mvc.UI;
EDIT
It seems Map is not supported in kendo or some .js sequence i am missing or something overriding?
On a shared view (like _layout.cshtml), I'm asking for the root folder in many ways ("/Content/design.css", #Url.Content("~/Content/design.css") ) But I'm always getting the controller name and then the requested url ("localhost:3333/MyControllerName/Content/design.css")
Why?
I'm running my project on IIS express.
This is the problematic line:
<link rel="stylesheet" href="#Url.Content("~/Content/design.css")" />
also tried:
<link rel="stylesheet" href="#Url.Content("/Content/design.css")" />
not sure if you fixed this, I know I'm late, can you try this?
I'm thinking you don't need #Url.Content
<link href="~/Content/design.css" rel="stylesheet" />
I'm getting this error when I start my project
It is being caused by the css and js files in the master page.
<link href="../assets/css/jquery.ui.theme.css" rel="stylesheet" type="text/css" />
When I remove this line the project starts functioning correctly(without the style)
Any ideas
Sp
Since this is ASP.NET, use a tilde ~ to mark the application root:
<link href="~/assets/css/jquery.ui.theme.css" rel="stylesheet" type="text/css" />