MVC Validation Lower/Higher than other value

前端 未结 5 1903
北恋
北恋 2020-11-30 00:52

How is the best way to validate a model in MVC.Net where I want to accept a minimum/maximum.

Not individual min/max values for a field. But separate fields for a use

5条回答
  •  自闭症患者
    2020-11-30 01:16

    There is a NuGet package called Foolproof which provides these annotations for you. That said - writing a custom attribute is both pretty easy and good practice.

    Using Foolproof would look like:

    public class FinanceModel{
       public int MinimumCost {get;set;}
    
       [GreaterThan("MinimumCost")]
       public int MaximumCost {get;set;}
    }
    

提交回复
热议问题