how to send input value to control using querystring Asp.net?

Asked

Viewed 448 times

-4

I have this code on View

    @using (Html.BeginForm("VisualizaJogoParaExclusao", "Relatorios", FormMethod.Post))
    {

        <div class="row">
            <div class="span12">
                <input class="form-control input-lg " id="NumeroJogo" required onkeyup="somenteNumeros(this);" placeholder="número"  type="text"  />
            </div>
        </div>

        <br />


        <div class="row">
            <div class="span6">
                <button class="btn btn-lg btn-block btn-primary glyphicon glyphicon-search" type="submit" value="pesquisar">  Pesquisar</button>
                <a href="@Url.Action("Index", "MenuPrincipal")" class="btn btn-lg btn-block btn-warning ">
                    Retorno
                </a>
            </div>
        </div>

2 answers

1

Change of FormMethod.Post for FormMethod.Get that the field value will be sent as querystring.

  • could you give me an example of how to receive this in the controller? thank you

0


  1. Change the form to FormMethod.Get
  2. Add name to input
  3. Grab the result from the controller int idDoregistro = Convert.ToInt32(Request.QueryString["NumeroJogo"]);
  • 1

    you could do your action with the following signature: public ActionResult NomeDaAction(int NumeroJogo) that the input with the property name="NumeroJogo" will be implicitly converted to int not needing to use Request.QueryString["NumeroJogo"]

Browser other questions tagged

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