MVC error 404 POST method

Asked

Viewed 401 times

0

This is my controller:

[HttpPost]
public ActionResult TestePost(int id1)
{
    ViewData["Teste"] = "O método POST funcionou, você digitou: " + id;

    return View("Index");
}

   [HttpGet]
    public ActionResult TesteGet(int id)
    {
        ViewData["Teste"] = "O método GET funcionou, você digitou: " + id;

        return View("Index");
    }

Below my view:

@using (Html.BeginForm("TesteGet", "Home", FormMethod.Get))
{
    <fieldset>
        <legend>Form tipo GET</legend>

        <input type="text" name="id" id="idGet" value="" />
        <input type="submit" name="enviar" value="enviar Get" placeholder="apenas numeros" />

    </fieldset>

}
<br/>
<hr/>
<br/>
@using (Html.BeginForm("TestePost", "Home", FormMethod.Post))
{   
    <fieldset>
        <legend>Form tipo POST</legend>

        <input type="text" name="id1" id="idPost" value="" />
        <input type="submit" name="enviar" value="enviar Post" placeholder="apenas numeros"/>

    </fieldset>


}

<h1>@ViewData["Teste"]</h1>

My problem: Method GET works perfectly, method post doesn’t work. Rebound: When is localhost works perfectly POST and GET when I put in Locaweb gives this error.

  • You published on Ocaweb?

  • 5

    Unfortunately yes.

  • 1

    One more soldier down!

  • Cara goes to Redehost or Umbler, because Locaweb is just a headache, I’ve been there.

1 answer

0

Your second form is with different Ids than expected by Controller.

@using (Html.BeginForm("TestePost", "Home", FormMethod.Post))
{   
    <fieldset>
        <legend>Form tipo POST</legend>

        <input type="text" name="id1" id="id1" value="" /> <!-- ID1 e não IDPOST -->
        <input type="submit" name="enviar" value="enviar Post" placeholder="apenas numeros"/>    
    </fieldset>    
}
  • Thank you for your attempt but without success. The problem is the Ocaweb server that does not know how to handle mvc applications.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.