c# - Must data-val-required and data-val-number have the same error messages -


data-val-required and data-val-number Are the same error messages?

I'm just thinking because I'm seeing the output of my HTML.

  & lt; Div class = "form-group" & gt; @htmllabelfor (m => m. Country) & lt; Div class = "row" & gt; & Lt; Div class = "col-lg-4" & gt; @ Html.DropDownListFor (m = & gt; m.CountryId, New SelectList (Model.Countries, "Id", "Name", Model.CountryId), "- Select -", New {@ class = "form-control" }) & Lt; / Div & gt; & Lt; / Div & gt; @html Validation message (x = & gt; x country id) & lt; / Div & gt;  

My viewload looks like this:

  Public class MyViewModel: ViewModelBase {public MyViewModel () {countries = Enumerable.Empty & lt; CountryDTO & gt; (); } [Required (Error Message = "Country Required")] Country Full Country {Received; Set; } [Display (name = "country")] Public INIM Marketplace & lt; CountryDTO & gt; Country Set; }}  

The HTML shown above looks like this:

  & lt; Select name = "country id" id = "countryId" data-val- required = "country is required" data-val-number = "country country id number." Data-val = "true" class = "form-control" & gt; & Lt; Option value = "" & gt; - Select - & lt; / Options & gt; & Lt; Option value = "1" & gt; Country 1 & lt; / Options & gt; & Lt; Option value = "2" & gt; Country 2 & lt; / Options & gt; & Lt; Option value = "3" & gt; Country 3 & lt; / Options & gt; & Lt; Option value = "4" & gt; Country 4 & lt; / Options & gt; & Lt; / Select & gt; Why are there 2 different messages in   

why the data-val-required and data-wall-number ? Should not they be equal?

No, when the user does not make any input available at all, while the input number is not provided , When the number is displayed.

You can see it in the same way that you can provide information to the user in the required error message, why the field is required, while in the number-error message you can provide additional information to the user , The field should be numeric


Comments