Quick hacks vs doing it right with MVC3 dropdowns

by Ryan Fri, July 08 2011 18:24

An obscure issue popped up today and it was a bit of a pain to track down. A user with IE6 (this is going to go on for YEARS) could not post a form back on a website because even though they selected a number from a dropdown list, it failed validation and told them that they 'must select a number'.

All the fancy javascript jQuery and unobtrusive data annotation validation was working, except for this glitch.

 

Now you can't just tell these people to upgrade their browsers (well, you can, but good luck with that) as they still represent a LOT of money in the marketplace, I'm talking about thousands of pounds a week for one site owner.

Luckily I keep a few virtual machines of XP with IE6 on them for just this and could see the same behaviour myself. The dropdown looks like this (in MVC3 Razor markup);

   @Html.DropDownListFor(i => i.Quantity, new System.Web.Mvc.SelectList(new[] { 1, 2, 3, 4, 5 }, "Value", "Text", Model.Quantity), string.Empty, new { @class = "dish" })

This is a quick way to generate a dropdown list and populate it with a range of values. It outputs the following HTML;

<select class="dish valid" data-val="true" data-val-number="The field Quantity must be a number." id="SideDishes_1__Quantity" name="SideDishes[1].Quantity"><option value=""></option>
<option selected="selected">1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>

This looks OK to me and works in every other browser I've tried, but it seems that IE6 INSISTS on the 'value=1' field for each option. I would have expected the DropDownListFor method to output this anyway but if you bind to a simple list of native types (integers in this case) then you can't set the data field and the value field for the option element (an integer does not have properties, it just 'is'). To fix it, you need to go verbose in the code and do something similar to the following;

   @{
      var values = new[] { 1, 2, 3, 4, 5 }.Select(x => new System.Web.Mvc.SelectListItem
      {
         Value = x.ToString(),
         Text = x.ToString()
      });
      values = new System.Web.Mvc.SelectList(values, "Value", "Text", Model.Quantity);
   }
   @Html.DropDownListFor(i => i.Quantity, values, string.Empty, new { @class = "dish" })

Yes, it's ugly and I could make it a LOT better but it works. The option HTML output is now what IE6 expects;

 

<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>

 

I'm impressed by how compatible the jQuery team has made the validation so that it even works in IE and the only thing that broke was a false expectation of the dropdownlistfor method.

This bug took me a good hour to sort out with the Virtual Machines and testing, hope this post helps you sort it quicker. The workaround is from the following StackOverflow blog post on binding to integers

Tags:

Blog | MVC3

Micro Framework, jQuery, dynamic .Net & swag for xmas

by Ryan Fri, October 29 2010 14:13

Next Generation user group have a lot of goodies coming up to Christmas followed immediately by the tech equivalent of some cracking January sales.

First up, in November we’ll be demonstrating the really cool .Net Micro Framework running on real hardware. If you don’t know what Micro Framework is (MF for short) then it’s pretty much .Net on a chip. Why the fuss you may ask? Well, you can do some pretty cool things with it, from building remote control planes and cars to automating your home.

Ryan will be building a caller ID unit in C# and giving away some sponsored MF hardware (courtesy of Gus @ tinyclr.com). Richard will be doing a ten minute ‘nugget’ on Atomiq and Nitriq, two productivity tools for .Net (they’ve sponsored us for some licences too).

The FEZ Domino Micro Framework board (right) with an Arduino Ethernet board (shield)

George Adamson is coming along in December to do his jQuery thing. George is VERY entertaining and has been rated as the top speaker at previous events. We’ll also be giving away an Xbox 360 in a raffle although you must be a paid up member to win.

January sees the return of the globe-trotting, ex- standup comedian Mark Rendle (don’t worry, he’s still funny) who will be doing his highly rated ‘Dynamic Alchemy: Real-world uses for dynamic C#’. Mark’s a favourite of ours as his talks are engaging, funny and very informative.

Now, swag! We are very lucky in Hereford because not only do we get swag from DevExpress, Telerik and JetBrains (over 1.5k of licences each month) but also occasional top-ups from Microsoft and other community oriented people such as Red-Gate and TinyClr.com.

You can come along twice without joining and see if you like it, then we ask you to join so we can cover speaker expenses, food and venue costs (we don’t make a profit, very dot com like). We provide the pizza and drinks, you just turn up (don’t forget to register on the website first, or no pizza for you!).

You can find us @ http://nxtgenug.net/Hereford, we meet once a month in Hereford Shire Hall (plus Birmingham, Coventry, Cambridge, Southampton, Oxford and Manchester too).

Tags:

nxtgenug

Visual Studio 2010 - buggier than 2008?

by Ryan Sun, June 13 2010 14:05

Buggy, definitely. Worth the hassle, yes.

The following occurs when trying to compare two schemas using the Data->Schema Compare->New Schema Comparison menu option and selecting two existing connections. Clicking 'Edit Connection' when the connections are selected you can't edit them either (the dialog just disappears) and after a few attempts, VS goes bang! To work around this error, go to Server Explorer and delete any old connections (you may need to delete them all to get it working).

You might get this a few times;

You'll need to quit VS and start again once that error starts popping up then the dodgy connections should have gone. If they are still there, keep hacking through them trying to delete (ignoring the errors) and restart again. If you still can't get rid of the dodgy connection, try expanding the node for it in server explorer. I got the following error which gave me a GUID I could hunt through the registry for to delete the data provider. Turned out my issue was caused by the VistaDb uninstaller removing the required files for a connection (which is what I wanted) but Studio fell over when it saw the headless connection.

I found some references to the dodgy connection under; HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\DataSources\{GUID-OF-PROVIDER-HERE}. After deleting all the references in the registry to it and the .suo file for the solution I found it was held elsewhere. So on with the hunt.

So far, one hour spent on this and no joy. Searching the C drive for all .udcx files (seems these hold connections) yielded nothing either, but very slowly. Reset the development environment (/resetskippkgs and /resetsettings as command line options to msdev), nowt.

Finally I fired up SysInternals Process Monitor and waded through the torrent of data it vomited when VS starts up. I happened across the directory; C:\Users\Ryan\AppData\Roaming\Microsoft\VisualStudio\10.0\ServerExplorer In there is a file ending in .SEView, this is where this junk is held.

I copied the file to a backup in the same directory (mistake) and tried again after editing the file, but the duff connection reappeared! Looking in Process Monitor, VS loads ALL files in that directory ending in SEView, so I moved them out completely and all started up well. Success, I can now compare two databases, two hours later!

The time technology saves me!

Tags:

Blog

Windows Mobile 7 by Paul Foster from Microsoft

by Ryan Mon, May 10 2010 22:25

Just a quick post to keep this thing up to date (and attract blog spam, I love it). We had an excellent speaker tonight at our user group in Hereford; Paul Foster from Microsoft presented on a ton of stuff in Windows Mobile and how to develop for it. He made it look easy but the designer tools scared me somewhat with their black turtle neck style UI and 'layers'. 'tis worth getting a look at Win Mo 7 before things pick up as devices are due to launch in the late Autumn and getting code working now on the emulator will place you in a good position for launch.

I recommend checking Paul's blog, the Windows Phone dev site and the XNA site to get up to speed on Win Phone.

Also, we had a good swag giveaway with decent T-Shirts, loads of MS Visual 2010 stuff (silly putty, screwdrivers, mice of the non-rodent variety) and a Windows 7 licence that MS gave us months ago and I found in the bottom of the swag cupboard. Everyone got something (I nabbed some silly putty). Thanks again Paul, I recommend you to get him at your user group (what, you don't have one!).

Tags: ,

Blog | nxtgenug

Book review: Web startup success guide

by Ryan Fri, January 22 2010 20:41

I've been taking my time reading this book as I've got so much out of it, I keep pausing to try out the ideas. It is not a typical computer book, it's for people who have plenty of ideas and are looking to put them into practice in starting up a new web based business. Targeted at software developers turned entrepreneur it also works well for anyone servicing customers over the web and trying to create a decent online presence.

The book is very motivating and well written. The author Bob Walsh also publishes a free podcast on the subject of startups (The Startup Success Podcast) so you can see if what he has to say is of interest before shelling out for the book.

I would definitely recommend this book as it is very useful in helping plan your startup and hopefully will save you a bundle of mistakes.

The obligatory link to Amazon:

Tags: ,

Book review | Business

Book review: iPhone Application Sketch Book

by Ryan Thu, November 19 2009 15:20

150 pages of identical iPhone outlines with room to sketch and label your designs. Not a great read, but handy nonetheless!

There's not a lot to say about this book, it's pretty basic but very useful for scribbling down ideas if you don't have Balsamiq Mockups to hand, are on the move or going into a meeting. I'm going to give copies to clients in the hope that they'll think about their app a bit more before asking for a thousand buttons on screen.

You can get it at Amazon and I imagine B & N (but I can't find it).

Tags:

Book review

Book review: iPhone for work

by Ryan Sun, November 01 2009 11:20

iPhone for Work: Increasing Productivity for Busy Professionals or 'The missing iPhone manual'

I thought I knew pretty much all there was to know about the iPhone but I'm happy to say that I've found out a few more tricks thanks to this book. For example, did you know that you can take a screenshot by using an obscure (almost Windows like) button combination? Or that you can set up a WiFi network between your iPhone and Mac without a wireless router? You might have known how to, but I didn't and judging by the lack of Apple documentation I guess a lot of other people are missing out a fair chunk of detail too.


It starts simple (too simple for me, but great for people who don't spend all day playing with computers) by walking the user through activating the phone, sending text and making basic calls. I skimmed these bits and got straight to the WiFi, Exchange, Calendar and LDAP sections which you'll need to know if you want to sync the iPhone with a corporate network.

Although the book is targeted more at the general iPhone user than IT professionals I think alpha geeks will learn a thing or two from it as well and afterwards they can give it to their relatives to lessen the support load. Apple should have shipped this book with the iPhone but I suppose it won't fit into a trendy little black box in a non-shredded form!

The best tip I got from the book means I can now control my laptop slideshows from the iPhone without worrying about needing a router (something that not all venues have). You can pick up a copy of the book at Amazon (in theory I get a referral fee, in practice it goes on swag and pop for the Hereford nxtgen user group).

Tags:

Book review

Test Driven Development in .Net - Hereford

by Ryan Wed, September 30 2009 11:08

Richard Hopton, coordinator for the Oxford nxgenug group will be delivering a fact packed talk on why we should write tests before code and how it improves the quality of the shipped code.

Hopefully he'll be able to help with the politics of developing. What politics you say? Well, when you tell your client that they can't have features 21 through 32 because you need the time to write tests and you can't deliver stable code in the time allotted. I've often heard people say they would rather hear the truth but when you say that their software build will take time to be up to quality, suddenly they are a software expert!

As Richard has been doing TDD for some time he knows how to get the quality angle across to clients, or perhaps he just hypnotises them.

I'll be doing a nugget (probably on sitemap generation but I'm not sure yet), more details can be found at the nxtgenug site.

So come along to Shire Hall on Monday the 19th of October 2009 just before 7pm for entertaining education, pizza and swag (including Telerik and Resharper licence giveaways).

Tags:

nxtgenug

XNA developer day - from basics to pixel shaders

by Ryan Tue, September 29 2009 17:25

The user group I'm part of (nxtgenug) is running a developer day in Birmingham, UK on December the 5th 2009. Everyone welcome and it costs £10 for the whole day (includes pizza, maybe some swag and drinks), you don't have to be a member of the user group but you do need to register first.

It's a Saturday too so no need to take a day off work. I'm going, but don't let that put you off!

See the nxtgen XNA event page for details.

Tags:

nxtgenug

Free iPhone app development, design and hosting!

by Ryan Tue, September 29 2009 15:27

That got your attention didn't it? Yes, you've found the only iPhone app developer on the internet who will prototype your design, create the visuals, develop the website, backend database, web services (for push notifications) and handle search engine optimisation. Heck, you can even use my $99 Apple Developer Program registration to get it published!

You've probably thought long and hard about your app idea and you reckon it can make you a lot of money, but you don't know how to develop software and that's where I come in. The software part is the easy bit, right?

Hey, perhaps you'd like to stay at my house rent free while I develop your software too? It'll be nice and quiet so you can carry on thinking about your idea in peace because my wife will have left me due to never seeing my face while I'm working 120 hours a week on other people’s ideas, unpaid.

If you want company it won't be long before the phone starts to ring off the hook with the bank calling to ask why the mortgage has not been paid. You see, while I'm working on your idea I won't be paying my mortgage because (you might want to sit down here), I'm not rich and I don't have caviar and salmon washed down with a bottle of Bollinger as the starter to a six course meal hand prepared by my faithful staff each evening. I don’t have a super hero cloak that magically protects me from the economy.

OK, in case you've not got it yet, I'm being sarcastic. I reckon most people reading this will understand that I need to make money and perhaps think I'm exaggerating about the 2-3 emails I get each day asking for cheap / free / sweat equity shared app development. I'm not joking, really, some of these are downright rude and they are not 'a friend of a friend told me' stories, they happen to me every day.

The emails / calls I get must be in the Outlook template list under 'I have an idea but no money', they seem to be run through a Bayesian filter first as they vary a little, but not by much. There are a few types of email / surreal conversation I generally get.

  1. We are a charity, that's great, but I'm not! I can't tell the bank to hold off on the mortgage because I'm working on charity projects can I? Well I could, but they wouldn't listen and would promptly kick me out. I've no problem with charities but I just can't afford to work for free.
  2. I've got a great idea but I don't want to tell you in case you steal it, how much to develop it? Hmm, let me nip into my time machine, ask my future self how much I should charge for the project they just developed, write down the cost, come back and then wipe my mind so I don't infringe your intellectual property. Or shall I say anywhere between £3,000 and £90,000 and you get all smart with me because you think I'm being cheeky!
  3. I've got a great idea, it's going to make loads of money, sign this NDA before I'll talk to you and by the way, I have no money so can you do it for free / cheap / a tiny share? Um, for all the reasons above and many more, NO! If your idea is so good and guaranteed to succeed then mortgage your house, sell your car, Xbox etc., after all, the risk is minimal and you'll be able to buy a bigger house or car in six months. It's not like the idea won't work is it?
  4. The very rare 'I've got an idea, how much to develop, that sounds fair' email. Not seen in the wild very often but is often sent from someone in the industry (web or software) who has a clue. I like these ones, keep 'em coming.

Perhaps they think software is easy. If so then why does most of it crash, look awful, not install and fail to meet basic customer expectations? Here's a clue, because it's not easy and the software that does fail on a regular basis has probably been developed by someone who thought software development isn't hard.

Or perhaps they think all of the hard work has been done on the extensive design documents (you know, the back of the cereal packet they scribbled on, but can't find it now, maybe it's in the bin with their other ideas).

I've been involved in sweat equity arrangements before and I know why they mostly don't work. It's because the other party has not committed anything apart from their 'great idea', after all that's the hard bit (so they think). I ended up developing systems to the value of £10,000 - £20,000 in my spare time, if I quit then I've lost six months of my life, if the partner quits then they have usually lost nothing. I’ve learned lessons, painful ones.

If you can find anyone who will develop, design the visuals, set up the web services, hosting and maintain support, let me know. I've got so many 'sales' leads I could put their way that they'll end up making a bigger loss than Bernie Madoff!

You can't believe how hard it has been to not swear during this tirade, but it's great to get it off my chest. Guess I'll ask Jeeves to warm the Bentley up, I fancy a tour round the estate after all this writing. Nah, sod it, I'll go rustic and use the Range Rover.

Tags: , ,

Rant | iPhone | Business