Return and assign to a query result textbox

Asked

Viewed 249 times

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, as I can record it and play it as a parameter for the query ?

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

I’ve tried the following so far:

Class of data access:

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>

1 answer

2


You have two ways of doing it.

Use a Viewbag:

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

And in View:

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

Or else send the data from your model from the controller:

return View("Detalhes", bm);
  • didn’t work. : S

  • So, what mistake are you making? Or what problem are you having?~

  • I tried this way you spoke and returned in the textbox a line of view code.

  • You did the first method then, right? Erase the (string) in the view

  • It sucks, he tells to do a cast that was in the case what I took and still doesn’t work ..

  • Try to give me more details

  • I forgot the "txtTitle", in the case put with the name of my field but still, is taking the name of the model.

Show 2 more comments

Browser other questions tagged

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