Click here to Skip to main content
14,579,188 members
Rate this:
Please Sign up or sign in to vote.
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:

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

Rate this:
Please Sign up or sign in to vote.

Solution 1

I want something like below:

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
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100