@Html.ValidationSummary() - how to set order of error messages

前端 未结 2 2009
迷失自我
迷失自我 2021-01-25 16:44

I have three form elements. We\'ll call them RadioA, RadioB, and Dropdown. In the Model they are created in that order, and presented in the View in that order, and specified a

2条回答
  •  无人共我
    2021-01-25 17:22

    I think a better way of doing this is to order the properties in your model in the same order you that you would like to display your validation messages:

    public class Ingredients
    {
        [Required]
        public string Vegetable { get; set; }
        [Required]
        public string Starch { get; set; }
        [Required]
        public string Meat { get; set; }
        [Required]
        public string Fruit { get; set; }
      }
    

    This will display a message in the following order:

    • The Vegetable field is required.
    • The Starch field is required.
    • The Meat field is required.
    • The Fruit field is required.

提交回复
热议问题