How to get the value of the input hidden inside the controller using FormCollection?

0

I'm trying to get the value of an input hidden inside the Controller by FormCollection, but the value is zeroed. To increase the value, I'm using a JavaScript function.

HTML:

  <form id="adicionarTituloManual" action="~/Movimento/AdicionarCodevedoresTit" method="post">
        <input type="hidden" id="qtd" name="qtd" value="" />
    </form>

Javascript:

function novo(i) 
   {
        var form, quant;

        var qtd = document.getElementById('qtd').value

        if (qtd == 0) {
            document.getElementById('qtd').value = i;
        }
        else{
            i =  parseInt(document.getElementById('qtd').value) + 1;
            document.getElementById('qtd').value = i;
        }
    }

Controller:

public ActionResult AdicionarCodevedoresTit(FormCollection formCollection)
{
    if (Session["usuario"] == null)
    {
        return Redirect("~/Home/Index");
    }
    else
    {
        this.usuario = (STLoginUsuario)Session["usuario"];
    }
    int qtd = HUtils.ConverteEmInteiro(formCollection["dvQtd"]);
    return Redirect("~/Movimento/AdicionarCoDevedor");
}
    
asked by anonymous 19.06.2017 / 13:43

1 answer

2

The FormCollection key must be the value of the name attribute of input .

The controller code should be something like

public ActionResult AdicionarCodevedoresTit(FormCollection formCollection)
{
    if (Session["usuario"] == null)
    {
        return Redirect("~/Home/Index");
    }
    else
    {
        this.usuario = (STLoginUsuario)Session["usuario"];
    }

    int qtd = HUtils.ConverteEmInteiro(formCollection["qtd"]);

    return Redirect("~/Movimento/AdicionarCoDevedor");
}
    
19.06.2017 / 13:54