Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

May be my subject could not clear the question but What I want is that I want to send each Suppliers TotalBalance along with Suppliers List and pass to View from Controller.

Hope you may understand that what I ant to ask.

What I have tried:

HTML
public ActionResult Index(Supplier sup)
        {
            var suppliers = db.Suppliers.Include(s => s.tblStatus);
            foreach (var x in suppliers)
            {
                ViewBag.SupTotalBalance = db.SupTotalBalance(x.SupplierId).SingleOrDefault();
            }
            return View(suppliers.ToList());
        }
Posted
Updated 22-Jun-20 7:42am
Comments
F-ES Sitecore 22-Jun-20 13:16pm    
I think you mean

ViewBag.SupTotalBalance += db.SupTotalBalance(x.SupplierId).SingleOrDefault();

you might have to define it as 0 at the top of your function.

A better way would probably be to just make a view model class that has properties for all the data you need rather than using a model and the ViewBag.

1 solution

I want something like below:

HTML
public ActionResult Index()
       {
           var suppliers = db.Suppliers.Include(s => s.tblStatus);
           List<string> sup = new List<string>();
           foreach (var x in suppliers)
           {
               sup.Add(x.Name.ToString());
               sup.Add(x.Address.ToString());
               sup.Add(x.Phone.ToString());
               sup.Add(x.Mobile.ToString());
               sup.Add(x.tblStatus.Status.ToString());
               ViewBag.SupTotalBalance = db.SupTotalBalance(x.SupplierId).SingleOrDefault();
           }
           return View(sup);
       }


but for now its giving me null error in x.Mobile
 
Share this answer
 
Comments
Richard Deeming 25-Jun-20 13:28pm    
If you want to update your question, click the green "Improve question" link and edit your question. Do not post your update as a "solution".

Also, if you want anyone to be able to help you solve an error, you need to provide the full details of the error. Just saying "I get an error" is not enough information for anyone to help you.
[no name] 27-Jun-20 17:25pm    
Ok Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900