Avoiding the message ‘A value is required.’ with ASP.NET MVC 2
This message (‘A value is required’) is the default validation error message that gets displayed with ASP.NET MVC 2 (preview 2 at the time of writing). The message shows up for each column in the model that fails validation when submitting a form.
The problem I came across was that if you have a column name of ‘Id’ in a table, when using LINQ to SQL, then the validation automatically checks for a value in this field provided to the model. This is great, apart from the fact that if it is an identity column, and therefore auto generating, then you don’t want to provide a value as it gets provided by the database. Fortunately, there is an easy way round this and it is to name columns things like PersonId or ClubId rather than just Id. This causes the framework to not autovalidate this column, and stops the validation message from showing up.
-
Calendar
February 2012 M T W T F S S « Feb 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 -
Meta





