How to receive a decimal value per Querystring in Asp.net?

Asked

Viewed 224 times

0

I have a form that sends some data, I want to receive this data but one of them is a value, is coming without the correct formatting.

@using (Html.BeginForm("GravarDados", "Aposta", FormMethod.Get))
{
    <div class="container droppedHover">
        <div class="row">
            <div class="input-prepend input-append">
                <input class="form-control input-sm " onkeyup="somenteNumeros(this);" id="numero" name="numero"  placeholder="número.." maxlength="4" type="text"/>
                <input class="form-control input-sm" type="number"  id="valor" name="valor" placeholder="valor.."/>
            </div>
        </div>
        <br />
        <button class="btn btn-primary btn-block " type="submit" >Adicionar</button>
    </div>
}
        public ActionResult GravarDados()
        {
            if (!String.IsNullOrEmpty(Request.QueryString["numero"]))
            {

                if (!String.IsNullOrEmpty(Request.QueryString["valor"])){

                    int IdDoUsuario = (int)Session["id"];
                    int numero = Convert.ToInt32(Request.QueryString["numero"]);
                    decimal valor = Convert.ToDecimal(Request.QueryString["valor"]);
                    var tTabela = new JogoTemAplicacao();
                    tTabela.Inseri(numero, valor, IdDoUsuario);

                }

            }

            return RedirectToAction("Index", "Aposta");
        }
  • Why does it have to be for QueryString?

  • I need a solution, whatever it is, I’m accepting.

1 answer

0


When you send the data from views to the controller by method GET as it is in the question, at the time of receiving the result, I must receive exactly as it comes and not make a value conversion:

Sent the value 10.20, was being done so:

decimal valor = Convert.ToDecimal(Request.QueryString["valor"]); 

Answer : 1020

But if I get the result in a string, I’ll have the result on the same formed typed:

string valor = Request.QueryString["valor"];

Answer : 10.20

At the time of recording in the bank I need to do the treatment as follows:

string.Format(CultureInfo.InvariantCulture, " {0:0.00}, ", VALOR_JOGO);

That solves the problem,

Browser other questions tagged

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