I realize this is an old question, but here is a modified version of dprothero's answer that will embed bundles.
Create a static C# class and put this method in it:
public static IHtmlString EmbedCss(this HtmlHelper htmlHelper, string path)
{
try
{
// Get files from bundle
StyleBundle b = (StyleBundle)BundleTable.Bundles.GetBundleFor("~/Content/css");
BundleContext bc = new BundleContext(new HttpContextWrapper(HttpContext.Current), BundleTable.Bundles, "~/Content/css");
List<BundleFile> files = b.EnumerateFiles(bc).ToList();
// Create string to return
string stylestring = "";
// Iterate files in bundle
foreach(BundleFile file in files)
{
// Get full path to file
string filepath = HttpContext.Current.Server.MapPath(file.IncludedVirtualPath);
// Read file text and append to style string
string filetext = File.ReadAllText(filepath);
stylestring += $"<!-- Style for {file.IncludedVirtualPath} -->\n<style>\n{filetext}\n</style>\n";
}
return htmlHelper.Raw(stylestring);
}
catch
{
// return nothing if we can't read the file for any reason
return null;
}
Then go to whichever view you want to use it in. Be sure to add a using statement so your view can see the CSS helper. I also use TempData to decide whether or not to render it inline:
<!-- Using statement -->
@using Namespace.Helpers;
<!-- Check tempdata flag for whether or not to render inline -->
@if (TempData["inlinecss"] != null)
{
<!-- Embed CSS with custom code -->
@Html.EmbedCss("~/Content/css")
}
else
{
<!-- Use links to reference CSS -->
@Styles.Render("~/Content/css")
}