0

I have this bit of HTML which should call /nodes/calibratePH?value=afloatnumber:

<div style="float:left; width:50%; margin-bottom:30px;">
<h3>PH calibration</h3>
<form id="CalibrationBar" action="/Nodes/CalibratePH" method="post">
    <select id=ids type="text" name="name">
        <option value="0" disabled selected>name</option>
        @{
            foreach (var configuration in Program.CAN_Listener.KnownConfigID)
            {
                if (configuration.type == Web_App.Models.Sensor_Types.PH)
                {
                    <option value="@configuration.name">@configuration.name</option>
                }
            }
        }
    </select>
    <input type="number" step="0.01" max="10.0" min="-10.0" placeholder="calibration value" name="value">
    <input type="submit" value="calibrate PH">
</form>
The problem is, when I enter for instance: 3.09 or 3,09 (doesn't matter). The method CalibratePH in the controller(MVC, ASP.NET) gets the value: 309. 1.1 gives 11, and so forth. Does anyone have an idea how to solve this? I'm thinking about entering the input as text and evaluate the value upon recieval in the method, but that's not how it should be... right?

EDIT: This guy seems to have sort of the same problem

Oscar K
  • 185
  • 1
  • 11
  • 1
    This means it is not picking the min and max range when the form is being submitted. Check if it is being reset somewhere before submission. You can also divide it in the api by 100, but I will recommend to see where is it being reset to its default values. – Jamshaid K. Nov 22 '21 at 13:42
  • Nope. doesn't look like the solution unfortunately. I removed the min and max just to be sure. No difference. As far as I can tell the value is not being reset before or on submission. – Oscar K Nov 22 '21 at 13:50

1 Answers1

1

I suggest you to make the parameter string on method calibratePH and when you receive it then cast it to float number.

Baskovli
  • 530
  • 5
  • 13
  • 1
    Yeah I was already thinking about this. I know this can work but it's just a less neat solution. I thought there would be a better one. THanks man – Oscar K Nov 22 '21 at 14:29
  • Another option is to add trailing slash to the end of the url. I have not tested it. Check here https://stackoverflow.com/questions/21387974/why-is-my-web-api-method-with-double-args-not-getting-called – Baskovli Nov 22 '21 at 14:39