BeginForm does GET instead of POST

1

I have a controller that has two Actions;

public ActionResult Cadastrar()
{
    return View();
}


//[ValidateAntiForgeryToken]
[HttpPost]
public ActionResult Cadastrar(Usuario usuario)
{
    if (ModelState.IsValid)
    {
        var appUsuario = new UsuarioAplicacao();
        appUsuario.Salvar(usuario);
        return RedirectToAction("Index");
    }
    return View(usuario);
}

And I have this view

@using (Html.BeginForm("Cadastrar","Usuario",FormMethod.Post)) 
{
    código código código
    <input type="submit" value="Cadastrar" class="btn_login" />
}

When I click submit on the registration page it goes to the same page sending by get the values of the form:

  

link

And when this happens it calls the register by get and the cycle repeats itself.

I can not register at all, does anyone have any tips?

    
asked by anonymous 09.10.2016 / 02:18

1 answer

0

The code snippet where you put "code" code should actually be the most important to solve your problem.

If you have not omitted the values of purpose in: link

I would say that your model is going null for the server and in the action overload Register it is choosing to register it from above (without parameters).

Mark the above with the decoration [HttpGet], to prevent it from responding to POST and check if your view is correct, especially the name of the input tags.

Many times the modelBind does not work as expected and the model arrives null, which causes these problems of the wrong action to respond to the request ...

I hope it helps ...

    
20.04.2017 / 12:10