mercredi 31 janvier 2018

Keep Radio and Checkbox value after submit in Razor page

I have the following code:

<div>
    <form method="post">
    <div>
        <input id="BatteryPercentage" min="0" max="100" name="BatteryPercentage" value="@Model.BatteryPercentage" type="number" placeholder="Insert Battery Percentage (0->100)">
        <button type="submit" asp-page-handler="BatteryPercentage">UPDATE!</button><br>
        </div>

                <div>

        <input type="number"  id="ACtemperature" min="15" max="30" name="ACtemperature" value="@Model.ACtemperature" placeholder="Insert AC Temperature (15°->30°)">
        <button type="submit" asp-page-handler="ACtemperature">UPDATE!</button><br>

        </div>
                <div>

        <label>Insert AC Power: </label>
        <input type="number"  id="ACpower" min="0" max="4" name="ACpower" value="@Model.ACpower" placeholder="Insert AC Power (0->4)">
        <button type="submit" asp-page-handler="ACpower">UPDATE!</button><br>
        </div>
                        <div>

            <label>Insert AC Direction: </label>
            <input type="radio" value="Model.ACopt1" name="ACdir"> 1 
            <input type="radio" value="2"  name="ACdir"> 2 
            <input type="radio" value="3"  name="ACdir"> 3 
            <button type="submit" asp-page-handler="ACdirection">UPDATE!</button><br>
            </div>
                    <div>


            <input  type="checkbox" name="ACopt1" value="1"> Opt1 
            <input  type="checkbox" name="ACopt2" value="2" > Opt2 
            <input  type="checkbox" name="ACopt3" value="3" > Opt3 
        <button type="submit" asp-page-handler="ACopt">UPDATE!</button><br>
    </div>

    </form>
 </div>

I want to keep the value of all input in my form after every submit. The "number" and "text" input are ok with the code "value="@Model.x" because in the chtml.cs I have:

        [BindProperty]
    public int BatteryPercentage { get; set; }
    [BindProperty]
    public int BatteryStatus { get; set; }
    [BindProperty]
    public int ACtemperature { get; set; }
    [BindProperty]
    public int ACpower { get; set; }
    [BindProperty]
    public int ACdirection { get; set; }
    [BindProperty]
    public bool ACopt1 { get; set; }
    [BindProperty]
    public int ACopt2 { get; set; }
    [BindProperty]
    public int ACopt3 { get; set; }

But this is not work with the radiobutton and checkbox. Any idea to solve?

Thanks.




Aucun commentaire:

Enregistrer un commentaire