IDataErrorInfo with MVC

Posts   
 
    
kievBug
User
Posts: 105
Joined: 09-Jan-2009
# Posted on: 19-May-2009 16:45:41   

Hi !

We are using LLBLGen and MVC. There is a small problem with validation that either LLBLGen or MVC has. We have an entity let's say Customer with field "name" and type nvarchar(50).

In UI user is trying to set name with 100 chars. Then DefaultModelBinder will try to bind this value to the entity and next sequence of actions will happen:

  1. DefaultModelBinder will try to set Name property of the entity
  2. LLBLGen will validate a new value and determine that it is bigger than allowed and will a) add this error collection(IDataErrorInfo) b) throw exception
  3. Default Model binder will catch this exception and will add it to Error collection(basically to ModelState)

So as a result two errors are added to ModelState and are shown to the user. What can you recommend to solve this problem?

Thanks, Anton

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 20-May-2009 06:33:24   

At step 3, the exception is thrown by LLBLGenPro (ArgumentOutOfRangeException ?) or by some Model method on your MVC app?

David Elizondo | LLBLGen Support Team
kievBug
User
Posts: 105
Joined: 09-Jan-2009
# Posted on: 20-May-2009 14:52:12   

There is only one exception throw - by LLBLGEN when DefaultModelBinder is trying to assign properties for the Model(which is Entity). So ModelBinder is calling setter then LLBLGen adds error to ModelState and throws an exception:

System.ArgumentOutOfRangeException occurred Message="The value specified will cause an overflow error in the database. Value length: 2350. Column max. length: 250\r\nParameter name: Name" Source="SD.LLBLGen.Pro.ORMSupportClasses.NET20" ParamName="Name" StackTrace: at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.ValidateValue(IEntityField2 fieldToValidate, Object& value, Int32 fieldIndex) InnerException:

This exception is caught by ModelBinder which adds this exception to ModelState too. So I get two messages in ModelState for the same field.

Anton

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 20-May-2009 15:11:21   

I'm not sure if we can do something about this, but I'm interested to know what you might suggest that could be done?