Return database value to textbox Asp.net MVC

Asked

Viewed 527 times

1

As return a value of a column of the bank sql for a textbox in asp.net mvc ? I created the textbox, created a property inside a class.

<label>
       @Html.DisplayNameFor(model => model.IRPJ) : 
       @Html.TextBox("txtIRPJ", Model.IRPJ , new {@class = "form-control form-control-custom", style="width:60px"})
</label>

How do I do that ?

I have a class beyond the model I’m doing like this:

 public BoletoModel IRPJ(string Tipo)
        {
            StringBuilder qryIRPS = new StringBuilder();
            qryIRPS.Append("Select Descricao1 ");
            qryIRPS.Append("from TiposNfsApp where ");
            qryIRPS.Append(" Tipo = '" + Tipo + "'");
            DadosNfsApp objDados = new DadosNfsApp();
            BoletoModel bm = new BoletoModel();
            DataTable dt = new DataTable();
            dt = objDados.RetornarDataSet(qryIRPS.ToString()).Tables[0];

            bm.IRPJ = dt.Rows[0]["Descricao1"].ToString().Trim();
            return bm;
        }
  • First describe in what Model this value is. ASP.NET MVC does not access only one column of a record, but the whole record at once.

  • @Ciganomorrisonmendez, to taking a stick of this mvc pqp. rs I will put as I did so far in the question.

  • Are you using Entity Framework? It is well out of the standard that you are doing.

  • No. Dude I don’t even know what I’m doing kkk. I’m completely lost in it. How nostalgic of webforms.

1 answer

1


You using your wrong View. Change to the following:

@model MeuProjeto.Models.BoletoModel // Preencha o nome da classe com o namespace. Aqui chutei um só pra você pegar a ideia.

<label>
       @Html.DisplayNameFor(model => model.IRPJ) : 
       @Html.TextBoxFor(model => modelIRPJ, new {@class = "form-control form-control-custom", style="width:60px"})
</label>
  • beauty, I tidied up here. But the process of returning from the bank the value I need a column passing a parameter, how can I do ?

  • This is not part of the question. Do another.

Browser other questions tagged

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