[RESOLVED]How to add Id attribute to link element in MVC Razor when using @Styles.Render

Hi,

In MVC _Layout.cshtml, we see this code.

@Styles.Render("~/Content/css")

And depending on how this bundle is configured, this translates as follows in the final html.

<link href="/Content/bootstrap.amelia.css" rel="stylesheet"/>
<link href="/Content/site.css" rel="stylesheet"/>

Now the question is, is there a way to add id attributes to the above link elements like so.

<link id="styleSheetLinkPath" href="/Content/bootstrap.amelia.css" rel="stylesheet"/>

Thanks

vivek

@Styles.Render only accepts one paramater, which is the path. So, I think it’s not possible to use it. Just use the link tag, but use @Url.Content in your href to make sure you get the correct path.

Hi vivek,

According to your description, you aren’t enable bundling and minification.

As jed0228 suggest that you could use link tag with Url.Content directly.

Best Regards

Starain

Leave a Reply