ArgumentOutOfRangeException was unhandled by user code

Posts   
 
    
hotmail
User
Posts: 47
Joined: 06-Feb-2013
# Posted on: 08-Jan-2015 21:22:14   

Using 4.2 latest. ASP.NET MVC 5.2 SQL server 2014

I have a simple form that post Person Data. PersonTestEntity has StringLength decoration

..PersonTestEntity..


        [DataMember]
        [StringLength(5, ErrorMessage = "The FirstName value cannot exceed 5 characters.")]
        public virtual System.String FirstName
        {
            get { return (System.String)GetValue((int)PersonTestFieldIndex.FirstName, true); }
            set { SetValue((int)PersonTestFieldIndex.FirstName, value); }
        }

Form


@model test.dal.EntityClasses.PersonTestEntity

@Html.ValidationSummary(true)
@using (Html.BeginForm())
{
    @Html.EditorForModel()
    <p>
        <button type="submit">Add Me</button>
    </p>
}

Controller


[HttpPost]
        public ActionResult PersonAdd(PersonTestEntity p)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }
            return View(p);
        }

when i type long text and click "Add Me" i get an exception and does not even go to PersonAdd method.


An exception of type 'System.ArgumentOutOfRangeException' occurred in SD.LLBLGen.Pro.ORMSupportClasses.dll but was not handled in user code

Additional information: The value specified will cause an overflow error in the database. Value length: 8. Column max. length: 5

but when i use Person Class


    public class Person
    {
        [StringLength(5, ErrorMessage = "The FN value cannot exceed 5 characters.")]
        public string FirstName { get; set; }
        [StringLength(5, ErrorMessage = "The LN value cannot exceed 5 characters.")]
        public string LastName { get; set; }
    }

and use this to post long test. it does go to PersonAdd method and see the error text on the form.

How can i display ErrorMessage on the form rather than getting an exception? Thanks

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 09-Jan-2015 09:07:18   

That's handled in the Built-In Validation, you can bypass it if you want. Please check Validation

Please check the following relevant thread: https://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=21884