1
Hello, I’m a beginner in C# and MVC and I’m having trouble returning a data list. I have the code below and do not know how to return the loaded data from the list. Can anyone suggest me how to do this? Thank you
public class EstoqueAcabadoController : Controller
{
// GET: EstoqueAcabado
public ActionResult Index()
{
using (BD context = new BD())
{
var query = from c in context.V500_ESTOQUE_ACAB select c;
foreach (var item in query)
{
ViewBag.cod_deposito = item.COD_DEPOSITO;
ViewBag.cod_reduzido = item.COD_REDUZIDO;
ViewBag.desc_cor = item.DESC_COR;
ViewBag.desc_artigo = item.DESC_ARTIGO;
ViewBag.peso_peca = item.PESO_PECA;
}
return ();
}
In fact, I’m learning the MVC. So I made a way to get a column just from my table, to play there in the view and it worked. Now, I want to take all the columns of my table (which is the query object) to play there in the view. Get it ? I think it’s a list right, I need to do. Thank you!!
– Jerry-SC
Ahhh Cleiton, you want to kind of put everything in one place ?
– Leonardo Bonetti
@Cleitondelims I recommend you create an object with the variables you want and pass the object as a whole. That would be it ?
– Leonardo Bonetti
I want for example to "load" the result of my select (with all columns) to show everything in the view, understand?
– Jerry-SC
@Cleitondelimas OK got it, explain something to me...
V500_ESTOQUE_ACAB
is an object with attributes:COD_DEPOSITO
,COD_REDUZIDO
,DESC_COR
,DESC_ARTIGO
andPESO_PECA
right– Leonardo Bonetti
In fact, v500_estoque_acab is the table of my database, and it has 30 columns. What I want is to bring all the columns of this table, and play as the controller’s Return, to be able to access my view and list the result of the query.
– Jerry-SC