0

I am coding a MVC 5 internet application, and have a question in regards to validating a integer value in a view.

I have a model with the following variable:

public int integerValue { get; set; }

If I enter a string value in the view for this model, I am getting an alert pop up that says:

Please enter a number.

This is not a normal validation message, and instead appears to be related to the browser.

My question is this: Is it possible to override this alert pop up to instead have the usual validation message beneath the input field?

Thanks in advance.

Simon
  • 7,991
  • 21
  • 83
  • 163

1 Answers1

0

That will be because Mvc has output an editor with input[type=number].

If you can live without the html5 spinner controls, you can try adding

 [DataType(DataType = DataType.Text)] 

to the property in question.

Or you can try

 @Html.EditorFor(m => m.{YourProperty}, new { htmlAttributes= new{ @type="text"}})
Slicksim
  • 7,054
  • 28
  • 32