Add field of decimal type Entity framework

Asked

Viewed 280 times

1

I have a Repair table in it I have Valuemade, Value and Total Value all of the decimal type. The Value field = Valuemaod + Value Library. However this returning 0. I am showing this in the Detail View when I click I will see the repair summary with its full price.

My Repair and Inspection/details

public ActionResult Detalhes(int id)
{
    decimal total = 0m;

    ConsertoVM model;
    using (Db db = new Db())
    {
        Conserto cons = db.Conserto.Find(id);
        decimal peca = cons.Pecas.ValorUnitatio;
        total += (cons.ValorMaoObra + peca);

        model = new ConsertoVM(cons);
    }

    return View(model);
}
  • I didn’t see where you’re setting the value in the field ValorTotal that you mentioned in the question, only in the variable total

  • You don’t have to do this so you can do it right in your View if it’s just to add a piece of data. what is inside Reparaovm, has access to the values of Cons?

  • i created a total variable that receives the sum of Value

  • - Ricardo Pontual - that was I only created the total variable just to see if it was getting the right value, however I was still not assigning the value to variable valueTotal, so it was showing 0, beginner né haha vlw

  • Put this operation in Reparaovm! and search for the method in your View! It’s that simple, what you’re doing won’t work

  • 4

    I’m voting to close this post because it was a small mistake that the AP has already solved with the help in the comments.

Show 1 more comment
No answers

Browser other questions tagged

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