Weird issue with input form on a simple ASP.NET core web application
-
I have a weird, or probably a simple dumb user error on a simple web application. The project is created with the wizard. (asp.net core web app with a new controller with EF). The database has been created and is working. I have a model (1 string, 2 double values):
public class Person
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public double Poids { get; set; }
public double Glycemie { get; set; }
}In the generated Create Page.
Addition : in the Create method, the value for the Glycemie is zero, as if it was not entered in the form. As if the binding did not work ???
\[HttpPost\] \[ValidateAntiForgeryToken\] public async Task Create(\[Bind("Id,Name,Poids,Glycemie")\] Person person) { if (ModelState.IsValid) { \_context.Add(person); await \_context.SaveChangesAsync(); return RedirectToAction(nameof(Index)); } return View(person); }
When I type in the data, name "Max" , poids (weight) "123" and glycemia 4.5 value, I get an error on the glycemia value saying the value is not valid. See image : [ ](https://imgur.com/a/jxiri42) When i just type 4 (instead of
-
I have a weird, or probably a simple dumb user error on a simple web application. The project is created with the wizard. (asp.net core web app with a new controller with EF). The database has been created and is working. I have a model (1 string, 2 double values):
public class Person
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public double Poids { get; set; }
public double Glycemie { get; set; }
}In the generated Create Page.
Addition : in the Create method, the value for the Glycemie is zero, as if it was not entered in the form. As if the binding did not work ???
\[HttpPost\] \[ValidateAntiForgeryToken\] public async Task Create(\[Bind("Id,Name,Poids,Glycemie")\] Person person) { if (ModelState.IsValid) { \_context.Add(person); await \_context.SaveChangesAsync(); return RedirectToAction(nameof(Index)); } return View(person); }
When I type in the data, name "Max" , poids (weight) "123" and glycemia 4.5 value, I get an error on the glycemia value saying the value is not valid. See image : [ ](https://imgur.com/a/jxiri42) When i just type 4 (instead of
I suspect the generated HTML will have an
<input type="number">
for both number fields. Unless otherwise specified, the defaultstep
for both fields will be1
, meaning that you can only enter integers: HTML attribute: step - HTML: HyperText Markup Language | MDN[^] Try specifying thestep
for both fields:
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
I suspect the generated HTML will have an
<input type="number">
for both number fields. Unless otherwise specified, the defaultstep
for both fields will be1
, meaning that you can only enter integers: HTML attribute: step - HTML: HyperText Markup Language | MDN[^] Try specifying thestep
for both fields:
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
thanks, I'll look into that.
CI/CD = Continuous Impediment/Continuous Despair