Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Weird issue with input form on a simple ASP.NET core web application

Weird issue with input form on a simple ASP.NET core web application

Scheduled Pinned Locked Moved ASP.NET
asp-netdatabasehelpcsharpdotnet
3 Posts 2 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Maximilien
    wrote on last edited by
    #1

    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

    Richard DeemingR 1 Reply Last reply
    0
    • M Maximilien

      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

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      I suspect the generated HTML will have an <input type="number"> for both number fields. Unless otherwise specified, the default step for both fields will be 1, meaning that you can only enter integers: HTML attribute: step - HTML: HyperText Markup Language | MDN[^] Try specifying the step for both fields:


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      M 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        I suspect the generated HTML will have an <input type="number"> for both number fields. Unless otherwise specified, the default step for both fields will be 1, meaning that you can only enter integers: HTML attribute: step - HTML: HyperText Markup Language | MDN[^] Try specifying the step for both fields:


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #3

        thanks, I'll look into that.

        CI/CD = Continuous Impediment/Continuous Despair

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups