Saturday 4 November 2017

MVC - fix error - Unable to cast object of type 'System.Int32' to type 'System.String'."

Watch on YouTube


How to set max length of integer

 1. Metadata file


namespace MVCValidationTest.Models
{
    [MetadataType(typeof(SelectTestValidation_Metadata))]
    public partial class SelectTestValidation_Result
    {
        //[StringLength(3, ErrorMessage = "{0} cannot be longer than 3 chars")]
        [Range(1,999)]
        public int test { get; set; }

2. View

  @Html.TextBoxFor(x => x.test, new { maxlength = 3 })

No comments:

Post a Comment