1

Model:

public class TransactionViewModel
{
    [Key]
    public int Transaction_Id { get; set; }
    public string Account_Name { get; set; }
    public string Type { get; set; }
    public string Note { get; set; }
    public DateTime Date { get; set; }
    public int Amount { get; set; }

    public IEnumerable<TransactionViewModel> Transactions { get; set; }
}

I want to validate models then by model validations concept I will do something like this:

[Required]
[StringLength(100)]
public string Account_Name { get; set; } = null!;

[DataType(DataType.Date)]
public DateTime date { get; set; }

and wherever we want we will just use:

if (!ModelState.IsValid)
{
}

but is there any other way to validate these models levels? as it is only specific to asp.net core, I want to know other ways of how to validate these fields

Please answer this

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
arunachal
  • 11
  • 2
  • What kind of model validation you are looking for which is `not specific to asp.net core` what did you mean by? Could you please share your scenario and expectations. Because the alternative way is also `specific to asp.net core`. The validdation stages are, `client side` and `server side`, in server side, default model validation which is `ModelState` and another way can be [`fluentvalidation`](https://docs.fluentvalidation.net/en/latest/aspnet.html) but this is also related to `asp.net core`. – Md Farid Uddin Kiron Feb 18 '22 at 02:10

0 Answers0