How to get a decimal value by QueryString in ASP.NET? [duplicate]

0

I have a form that sends some data, I want to receive this data plus one of them is a value, it 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");
        }
    
asked by anonymous 09.01.2016 / 19:17

1 answer

0

When you send the data from views to controller through method GET as it is in the question, at the moment of receiving the result, I should receive exactly as it comes and not do a conversion of the value:

Sent the value 10,20, it was being done like this:

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

Response: 1020

But if I get the result in a string , I'll have the result in the same form typed:

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

Answer: 10.20

At the time of writing to the bank I need to do the processing as follows:

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

This solves the problem,

    
10.01.2016 / 00:12