How to Add Media Attribute to ASP.NET Mvc4 Style Bundle

Make ASP.NET bundling specify media=screen for CSS bundle

I've found a more elegant solution.

I'm using the Styles.RenderFormat(format, bundle).

I have a BundlesFormats class with a property called PRINT and I use it like so:

public class BundlesFormats
{
public const string PRINT = @"<link href=""{0}"" rel=""stylesheet"" type=""text/css"" media=""print"" />";
}

And in the cshtml:

@Styles.RenderFormat(BundlesFormats.PRINT, "~/bundles/Content/print")

MVC4 bundle {version} wildcard chokes on non-numeric versioning

It sounds like the {version} regex should match semantic versions to account for the -pre/alpha1 suffixes. I'll add this to our backlog.

How to use bootstrap styles on print page with Asp.net bundling

According to this, Bootstrap 3 considers the paper page to be less than 768px wide, so it displays the mobile version of the page. You should probably create a special print stylesheet for the printed view.

Alternately, you should be able to get around this by adding xs classes to your grid, like this:

<div class="row">
<div class="col-lg-4 col-md-4 col-xs-4">
<h1>First Name</h1>
</div>
<div class="col-lg-4 col-md-4 col-xs-4">
<h1>Middle Initial</h1>
</div>
<div class="col-lg-4 col-md-4 col-xs-4">
<h1>Last Name</h1>
</div>
</div>
<div class="row">
<!-- Next row -->
</div>

This isn't a great idea though, because a printed view is different from a small viewport, so it's better practice to create a separate print stylesheet.

ASP.NET MVC4 dynamic form generation

There is no need for multiple POSTs. You want your form to send an array of Person to your action. The action will be something like

[HttpPost]
public ActionResult AddPeople(Person[] people){ ... }

To achieve that, you must enumerate the input fields on your view. They must be indexed, starting in 0 and incrementing accordingly, like:

@using(Html.BeginForm("AddPeople","TheController", FormMethod.Post))
{
<input type="text" name="people[0].FirstName" />
<input type="text" name="people[0].LastName" />
...
<input type="text" name="people[1].FirstName" />
<input type="text" name="people[1].LastName" />
...
<input type="text" name="people[n].FirstName" />
<input type="text" name="people[n].LastName" />
}

You must add the new fields using javascript, with a simple DOM manipulation. Just remember to keep the indexes in order.

Integrating Font Awesome, Less, Twitter Bootstrap and MVC4 bundling/minification

I ran into a similar problem with TinyMCE. When MVC packages the javascript into a bundle the resulting javascript threw an exception.

BundleTable.EnableOptimizations = false;

If you put that line in your RegisterBundles function in the BundleConfig class, that will turn off the bundle and let your site work in production. It won't minimize your javascript automatically but at least stuff will start working.

You could them minimize each javascript file manually to get the smallest footprint and hopefully find your problematic js file.

Images, CSS, and JS Not Loading in MVC4 App

Comment out this under system.webserver in web.config

  <staticContent>
<!-- <mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<mimeMap fileExtension=".m4v" mimeType="video/m4v" />
<mimeMap fileExtension=".ogg" mimeType="video/ogg" />
<mimeMap fileExtension=".ogv" mimeType="video/ogg" />
<mimeMap fileExtension=".webm" mimeType="video/webm" />
<mimeMap fileExtension=".oga" mimeType="audio/ogg" />
<mimeMap fileExtension=".spx" mimeType="audio/ogg" />
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
<mimeMap fileExtension=".svgz" mimeType="image/svg+xml" />
<remove fileExtension=".eot" />
<mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
<mimeMap fileExtension=".otf" mimeType="font/otf" />
<mimeMap fileExtension=".woff" mimeType="font/x-woff" />-->
<remove fileExtension=".manifest" />
<mimeMap fileExtension=".manifest" mimeType="text/cache-manifest" />
</staticContent>


Related Topics



Leave a reply



Submit