Return and assign to a query result textbox

1

How to return the result of a query and assign to a textbox in asp.net mvc?

The "Type" is a Textbox from another screen, how can I record it and pass it as a parameter to the query?

This method that I created the breakpoint does not fall because there is already a method that returns to that view.

I've tried the following so far:

Data access class:

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;
        }

Controller:

public ActionResult RetornarIRPJ(string Tipo)
{
        BoletoRepositorio br = new BoletoRepositorio();
        BoletoModel bm = new BoletoModel();

        bm.IRPJ = br.IRPJ(Tipo).ToString();

        return View("Detalhes");
}

Existing method that returns to the View:

public ActionResult Detalhes(string Fatura)
{
       var model = RetornarItemList(Fatura);

       return PartialView(model);
}

View:

<label>
        @Html.DisplayNameFor(model => model.IRPJ) : 
        @Html.TextBoxFor(model => model.IRPJ, new {@class = "form-control form-control-custom", style="width:60px"})
</label>
    
asked by anonymous 12.08.2015 / 16:33

1 answer

2

You have two ways to do this.

Use Viewbag :

bm.IRPJ = br.IRPJ(Tipo).ToString();
Viewbag.IRPJ = bm.IRPJ;

And in the View:

@Html.TextBox("txtTitle", (string)ViewBag.IRPJ , new {@class = "form-control form-control-custom", style="width:60px"})

Or you can send the data of your model from the controller:

return View("Detalhes", bm);
    
12.08.2015 / 16:37