How to call a function from razorview to cshtml.cs

Viewed 116

I'm new to razor views and I need to pass data from a form to razor view where you can put a number and take it from your cs in a method, then I also need to be able to do the opposite, take data from the cs (a number) and pass them to the razor view. My code actually contains this in the razor view:

@page
@model CountdownWebAPP.Models.CountdownModel
<form method="post">
    <table>
        <tr>
            <td>
                <label for="RemainingTime" class="col-form-label">
                    Enter the number of seconds you want to count down
                </label>
            </td>
        </tr>
        <tr>
            <td>
                <input type="number" id="RemainingTime" name="Remainingtime" />
            </td>
        </tr>
        <tr>
            <td>
                <button type="submit" value="Submit" class="btn btn-dark">Start</button>
            </td>
        </tr>
    </table>
</form>
    <table>
        <tr>
            <td>
                <label class="col-form-label">
                    Number of seconds missing:
                </label>
            </td>
            <td>
                <label class="col-form-label-lg">
                    
                </label>
            </td>
        </tr>
    </table>

and this in the cs code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace CountdownWebAPP.Views
{
    public class IndexModel : PageModel
    {
        private int time;
        [BindProperty]
        public int RemainingTimeP { get; set; }
        public void OnGet(int RemainingTime)
        {
            RemainingTimeP = RemainingTime;
        }
        public string EmailAddress { get; set; }
        public void OnPost()
        {
            var RemainingTime = Request.Form["RemainingTime"];
        }
    }
}

0 Answers
Related