Recover value from an HTTP

Asked

Viewed 109 times

1

I found a question four years ago that "would be" exactly what I need:

I have a URL where it returns an HTTP Querystring, and I need to recover URL information and convert into variables to make queries on database. In PHP just use $_GET[""], now in C# I do not know how to proceed.

Let me give you an example to clarify.

I have the URL: http://html.net/page.php?name=Joe&age=12

I have to take the values "Joe" and "12" for a later consultation.

And in that question you have the following answer:

string name = Request.Querystring["name"];

string age = Request.Querystring["age"];

But I am putting this "Request" in my view, and it presents the following error: "The name Request does not exist in the current context".

I put the namespace @using System.Net and @using System.IO that I found in other searches on google, but still unsuccessful, Request error continues. Even with Alt+Enter VS does not give any correction suggestions.

Any suggestions. Thanks.

[UPDATE] On request I am placing the code of the view that I need to recover the value passed by the URL.

@using SoftiseEVO.Classes;
@using System.Net;
@using System.IO;

@model IEnumerable<LanctoConferenciaCaixaModel>

@{
    ViewData["Title"] = "Consulta Caixa";

    string _idCaixa = Request.QueryString["idCaixa"]; //<= o erro está na chamaa do Request: "O nome Request não existe no contexto atual".

    string _dscaixa = "C002 CAIXA ANDERSON N"; //após ter o idCaixa, preciso buscar a descrição
    string _vlconferido = "0,00";

<div class="box box-primary">
    <!-- box consulta -->
    <form asp-controller="FechamentoCaixa" asp-action="LanctoConfCaixaAdministrativo" role="form" method="get" id="FormLanctoCaixa">
        <div class="box box-default" style="border-top: 0px;">
            <div class="box-header with-border">
                <h3 class="box-title box-success">Lançamento Conferência Caixa Administrativo</h3>
                <div class="box-tools pull-right">
                    <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                </div>
            </div>
            <div class="box-body">
                <div class="row">
                    <div class="col-md-6">

                        <input type="hidden" id="IDCXACAD" name="IDCXACAD" value="" />
                        @await Component.InvokeAsync(InputText.ViewComponentName, new { label = "Caixa", id = "IDCXACFGDIA", value = _dscaixa, readOnly = true, uppercase = true })
                        @await Component.InvokeAsync(InputTextConsulta.ViewComponentName, new { label = "Forma Pagamento", id = "IDFORPGT", valueId = "", valueCod = "", valueText = "", hiddenCod = false, onlynumberCod = true, maxlengthCod = "7", readonlyText = true, required = true, uppercase = true, autofocusCod = true })
                        @await Component.InvokeAsync(InputValue.ViewComponentName, new { label = "Valor Conferido", id = "VLCONFERIDO", value = _vlconferido })

                    </div>
                </div>
                <div class="row" style="margin-left: -10px;margin-right:-10px">
                    <div class="box-footer no-border">
                        <button type="submit" class="btn btn-softise" id="BtnConsultar">CONFIRMAR</button>

                        <a asp-area="" asp-controller="FechamentoCaixa" asp-action="GetFechamentoCaixa">
                            <button type="button" class="btn btn-default pull-right">CANCELAR</button>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!-- fim box consulta -->

</div>
}
No answers

Browser other questions tagged

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