0

I got attribute in sql server 2012 database of data type numeric (18,0), how I am going to model using data annotation in asp.net mvc-5 app.

this code giving me following error...

An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code

Additional information: The 'PassMark' property on 'MarkScheme' could not be set to a  'System.Decimal' value. You must set this property to a non-null value of type 'System.Int32'

Many Thanks

SQL Image

enter image description here

Model

 [Required(ErrorMessage = "Required Pass Mark")]
 [Display(Name = "Pass Mark")]
 public int PassMark { get; set; }

3 Answers 3

1

I would use the [RegularExpression]. like yzi_20004 but your issue is that you set

  public int PassMark { get; set; }

and it should be

    public decimal PassMark { get; set; }

hope this helps

Sign up to request clarification or add additional context in comments.

Comments

1

Use following attribute for validation -

[Range(0, 999999999999999999)]

And your C# property should be -

Updated EDIT

public decimal PassMark { get; set; }

3 Comments

@toxic Can you share actual Range code you used? and what error you got?
@toxic, have you used - [Range(0, 999999999999999999)]
yes i did and i am getting following error... Additional information: The 'PassMark' property on 'MarkScheme' could not be set to a 'System.Decimal' value. You must set this property to a non-null value of type 'System.Double'.
0

I always using [RegularExpression("^[0-9]{0,18}$", ErrorMessageResourceType = typeof(Messages), ErrorMessageResourceName = "ErrMsg_ID")]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.