Viewbag error: does not contain a definition for field name

Asked

Viewed 58 times

0

I got this Viewbag

ViewBag.LogAlteracao = _logAlteracaoRepository.Table.Where(log => log.OrderId == id).ToList();

That is the domain

public class LogAlteracao : EntityBase
    {
        public DateTime? Data { get; set; }
        public string Acao { get; set; }
        public string Localizador { get; set; }
        public string Observacao { get; set; }
        public int OrderId { get; set; }
    }

When I try to popular be a table or a list in the View, so for example

<div class="margin-40-b">
           <ul>              
               <li>
                   <label>Ação:</label>
                   @ViewBag.LogAlteracao.Acao
               </li>
           </ul>
        </div>

Caught that mistake

Message='System.Collections.Generic.List "Core.domain.Logs.Logalteracao"' does not contain a definition for 'Action'

What might be going on? I’ve already removed Tolist() and still nothing.

NOTE: I put double quotes, because the < or > sign was hiding the rest of the message when quoted

1 answer

1


The ViewBag.LogAlteracao that you’re going through is a list.

And the Acao is a property of a LogAlteracao.

Place inside a loop, access the ViewBag.LogAlteracao[i].Acao and be happy :)

Browser other questions tagged

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