Beginform makes GET instead of POST

Asked

Viewed 243 times

2

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 on Ubmit on the registration page it goes to the same page by sending get the form values:

http://localhost:51497/Usuario/Register? idUsuario=&Nome=&Email=&Password=&Permissao=

And when this happens he calls the register for get and the cycle repeats.

I can not register in any way, someone has some hint?

  • 1

    Enter the generated html code!

  • Better, https://github.com/marks5/meurepo_forsoft2/blob/testes/Forsoft2_tentativa6/Forsoft2_tentativa6/Views/Usuario/Cadastrar.cshtml

  • 1

    I’m finding it strange because the code is right, I actually wanted the code generated by the browser, the pure html by right-clicking display page code, I want to understand the generation

  • 3

    I spent the afternoon codando and found the problem. The cause of the problem was a nesting of forms. Even then I add an answer with research I’ve done. As I say a renderbody within a template that the frontend team passed me ended up unnoticed the previous form, so whenever the beginform made the post it climbed hierarchy. And well, it generated the Get. I appreciate your willingness to help me. :-)

No answers

Browser other questions tagged

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