M
M
marshmallo_w2018-12-03 16:37:28
ASP.NET
marshmallo_w, 2018-12-03 16:37:28

Why is OnPost request not working?

I started to study Asp Net Core 2. There is a razor page and the post request does not work in it: when you click on the button, it displays that the page is not available. If you send the get form with a request, then everything works. What am I doing wrong?
And how can you specify which handler the form should be processed with? I saw a way through asp-page-handler, but it didn’t work for me (I managed to connect only through a hidden tag)

@page
@functions
{
    public string Number1 {get; set;}
    public void OnPost(string numb2)
    {
        Model.Number1=numb2;
    }
    public void OnPostCalc(string numb1)
    {
        Model.Number1=numb1;
    }
}
<!DOCTYPE html>
<html>
    <head>
        <title>Razor Pages</title>
    </head>
    <body>
        <p>Здравствуйте! @Model.Number1</p>
        <form method="post" name="form1">
            <input type="hidden" name="handler" value="calc"/>
            <input type="text" name="numb1"/>
            <input type="text" name="numb2"/>
            <input type="submit" value="Посчитать" name="sub"/>
        </form>
    </body>
</html>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2018-12-03
@petermzg

The documentation says here
and an example is given of how this block of code is immediately called.
This is code execution at the time of page generation, not client-side code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question