Why is the Bootstrap class not being applied?

时间:2016-04-04 17:45:06

标签: css asp.net twitter-bootstrap asp.net-web-api

In the default/generic html provided in an ASP.NET app, the home page is rendered with the html in Index.cshtml, which starts out:

<div class="jumbotron">
    <h1>ASP.NET</h1>
    <p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS, and JavaScript.</p>
    <p><a href="http://asp.net" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>
</div>

This creates a "jumbotronified" section at the top of the page with a large "ASP.NET" within it.

However, when I try to use that bootstrap css class ("jumbotron") in another place:

StringBuilder builder = new StringBuilder();
builder.Append("<html>");
builder.Append("<head>");
builder.Append("<title>");
builder.Append(string.Format("Available Delivery Performance Reports For 
{0}", unit));
builder.Append("</title>");
builder.Append("</head>");
builder.Append("<body>");

builder.Append("<div class=\"jumbotron\">");
builder.Append(String.Format("<h1>{0}</h1>", unit.ToUpper()));
builder.Append("</div>");
. . .
builder.Append("</table>");
builder.Append("</body>");
builder.Append("</html>");

return builder.ToString();

I get nothing special - the jumbotronned h1 is rendered, but without the jumbotron "effect" I would think that if the bootstrap classes are available from one place in the project, they would be available anywhere in the project. What do I need to do to introduce this dynamic html to the bootstrap subsystem?

2 个答案:

答案 0 :(得分:3)

It looks like you are generating CSS for an entire new page (i.e. one that doesn't inherit from a Layout and isn't a partial view).

If that is the case, then you would need to explicitly referencing your Bootstrap files within this new generated page in order for them to be applied properly :

You could probably use something like :

// Example of adding in Bootstrap CSS
builder.AppendFormat("<link href='{0}' rel='stylesheet' />", Url.Content("~/Style/bootstrap.min.css"));
// Example of appending jQuery JS
builder.AppendFormat("<script src='{0}'></script>",Url.Content("~/Scripts/jquery.min.js"));
// Example of appending Bootstrap JS
builder.AppendFormat("<script src='{0}'></script>",Url.Content("~/Scripts/bootstrap.min.js"));
builder.Append("</head>");

Traditionally, these files would be referenced within a Layout or within the <head> section of a normal view, however since you are manually building the entire HTML content within your StringBuilder, you need to include any references in there as well.

答案 1 :(得分:0)

这(引用bootstrap和jQuery CDN)有效:

let artworkMetadataItem = AVMutableMetadataItem()
artworkMetadataItem.locale = NSLocale.currentLocale()
artworkMetadataItem.identifier = AVMetadataCommonIdentifierArtwork
artworkMetadataItem.value = UIImageJPEGRepresentation(image, 1.0) 
playerItem.externalMetadata.append(artworkMetadataItem)