Saturday, September 24, 2011

data-placeholder in MVC3

September 24, 2011 Posted by Jason Irwin , 1 comment
I ran into an interesting problem this evening with a very quick fix. I’m using the very neat chosen Javascript plugin (link) to add some aesthetic and functional sugar to a website’s existing dropdowns.

Anyhow, adding default text support (e.g. “Please choose an option”) to a multiple select dropdown is achievable using data-placeholder like this:
<select data-placeholder="Choose a country..." style="width:350px;" multiple class="chzn-select"">
Problem is, I am using ASP.NET MVC’s helper syntax to create my dropdownlists and “data-placeholder” is invalid syntax due to the dash character. The following does not work:
@Html.DropDownListFor(m => m.SelectedProductIDs, Model.AvaliableProducts.ToSelectList("ID","Name"), new { @class = "chzn-select", data-placeholder="Please select a product" })
Happily, Microsoft pulled a rabbit out of the hat and as of MVC3 underscores in html attribute properties are automatically converted to dashes, meaning that this:
@Html.DropDownListFor(m => m.SelectedProductIDs, Model.AvaliableProducts.ToSelectList("ID","Name"), new { @class = "chzn-select", data_placeholder="Please select a product" })
will generate something like this, with the place_holder converted to place-holder
<select class="chzn-select chzn-done" data-placeholder="Please select a product" id="SelectedProductIDs" name="SelectedProductIDs" style="display: none; ">

Tuesday, September 13, 2011

Saturday, September 10, 2011

gitignore–Don’t ignore Nuget Binaries

September 10, 2011 Posted by Jason Irwin , 1 comment
I am pretty new to the GIT world and am excited to be moving a personal project from Subversion to GIT. As with most .NET developers’ .gitignore files, I use the following line to filter out DLLs so that I am not versioning build DLLs

I ran into an issue where I wanted to exclude all DLLs except for those stored in my Nuget packages directory. This wouldn’t in itself be an issue were it not for the fact that Nuget packages diverge wildly with respect to the number of nested sub-folders. Where one package might store it’s DLLs one folder down the directory hierarchy, another might store theirs down 10…

I searched for a recursive wildcard pattern that would work via mysysgit but hit a brick wall as none of the following worked:


While I hoped for a cleaner solution it turned out that all I had to do was add another .gitignore to my packages directory containing only the following line:


Obviously this would work just as well for !*.exe or any other relevant binary file type…