locked
Trigger HttpPost action method on page load without a button RRS feed

  • Question

  • User1982683974 posted

    Hello

    I have a http post method and wanna post some data on the load of the page , the page doesn't have a button and that s the requirement.The issue is the action method is not even called 

    my action method :

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult SubmitPerson(string id, AdvisementModel model)
    {



    and in the view:

    using (Html.BeginForm("SubmitPerson", "Advisement", FormMethod.Post))
    {
    @Html.AntiForgeryToken()
    @Html.HiddenFor(model => model.Token)



    Friday, September 27, 2019 2:51 PM

Answers

  • User-474980206 posted

    odd requirement, the server does not really need to go to the client for this. the get action could build the model, and return the post method. anyway its simple, after the form add:

    <script>document.forms[0].submit();</script>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 27, 2019 3:35 PM

All replies

  • User-474980206 posted

    odd requirement, the server does not really need to go to the client for this. the get action could build the model, and return the post method. anyway its simple, after the form add:

    <script>document.forms[0].submit();</script>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 27, 2019 3:35 PM
  • User1982683974 posted

    thank you, I just called the post method from the get method and it worked

    Friday, September 27, 2019 3:43 PM