Friday 19 February 2010

Go away “The value '' is invalid”!!!

I’ve been busy working away on an ASP.Net MVC 2 project for the last week a half or so.
Just to get some background on this project. I’m using VS 2010 RC, SQL Server 2008 and the Data Entity Framework that comes with .Net 4.0. I’ve been using the objects created by the EF as my data model and have added the necessary Metadata for validation using an extra class in conjunction with the MetadataType attribute and partial classes. Please see Scott Guthrie’s excellent blog posting on this here http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx.

Everything was setup and I had a simple Title class with one property that had a required field attribute.

   1:  public class TitleMetadata
   2:  {
   3:       [DisplayName("Title")]  
   4:       [Required(ErrorMessage = "Title is required.")]  
   5:       public string MainTitle { get; set; }
   6:  }

I knew the Metadata class was being picked up by my model because the title was being displayed correctly.

<%= Html.LabelFor(m=>m.MainTitle) %>
<%= Html.EditorFor(m => m.MainTitle) %>
<%= Html.ValidationMessageFor(m=>m.MainTitle) %>

However, when I clicked the submit button leaving the Title field blank, instead of seeing the message “Title is required” I was setting "The value '' is invalid.”!

image

After some debugging I discovered that the message wasn’t coming from my metadata file or from MVC itself, but rather it was coming from the EntityFramework’s model. The scalar property I was binding to wasn’t set as Nullable and it was generating an exception in the setter.

image

Once I changed over the value Nullable in the Entity Model, my problem resolved itself!

image

Just something to watch for when using MVC with the EntityFramework!

Wednesday 30 December 2009

Ah, I’m so proud of how Irish people start their holidays…

IMG_0431[1]

Tuesday 24 November 2009

Chome says that GMail may not be secure??

After seeing a segment on “The Real Hustle” on Wi-Fi hacking, I enabled SSL on my Gmail account hoping that would ward off any hacker’s attempts to view my impressive of Viagra spam.

But I noticed that my Chrome browser had highlighted the address bar in yellow and clicking on the triangular warning icon, I was presented with this dialog box

 

image

 

Whilst I understand they cannot secure all elements of the page, it does after all, contain images from other websites, I think the language they are using is very confusing. It talks about unsecured resources and how they could be compromised by hackers! Scary stuff to the lay person.

Google do try and speak plain language, but this time they’ve dropped the ball. It’s no wonder that Chrome just isn’t taking off as the browser of choice!

Thursday 12 November 2009

HarmVille

At last, my revenge on the spam of FarmVille updates has begun! I've put into place the beginnings of a very simple app so that I can annoy FarmVille players without having to play FarmVille myself. Genius.

I'm going to put a very simple application up on either Google App Engine or Windows Azure to allow other people create the spoof news entries. Until the makers of FarmVille hunt me down and sue me.

I'll blog again when the application is ready to go!

Thursday 8 October 2009

Welcome to my new blog!

Decided it was time to start up my blog again and what better way to kick it off then to give it a major face life!

I’ve moved to Blogger and found a fantastic template thanks to http://speckyboy.com/2009/10/05/50-surprisingly-amazing-themes-for-blogger/

I’ll be setting up a redirect from www.chewedpencil.net to my blog address at blog.chewedpencil.net (the DNS records have just been changed).

This time around I hope to actually blog more!

Tom