Home > OS >  Number of suppliers by country MVC
Number of suppliers by country MVC

Time:08-09

supplier by country

I want the number of customers in that country to be written in the numbers "00" next to the countries. can you help?

With the html helper, I can classify suppliers on the basis of countries. but I could not write the number of suppliers in that country on the same line.

controller:

        public ActionResult SupplierList(int supID = 0, string country="")
    {
        ViewBag.supCountries= _db.Suppliers.Select(a => a.Country).Distinct().ToList();

        List<Suppliers> supplierList;


        if (country== "" && supID == 0)
        {
            supplierList = _db.Suppliers.ToList();
        }
        else if (country!= "" && supID == 0)
        {
            supplierList = _db.Suppliers.Where(a => a.Country == country).ToList();

        }
        else
        {
            supplierList= _db.Suppliers.Where(a => a.SupplierID == supID).ToList();
        }

        return View(supplierList);
    }

view:

    <div >
    <ul >
        @foreach (string item in ViewBag.supCountries)
        {
            <li >
                @Html.ActionLink(item, "SupplierList", new { country= item })
                <span style="float:right; color:lightgrey">
                    00
                </span>
            </li>
        }
    </ul>
    <div>
        @Html.ActionLink("New Supplier", "Create", null, new { @class = "btn btn-success" })
    </div>
</div>

CodePudding user response:

You passed the supplier list in as a model, so you should be able to replace 00 with something like

<span style="float:right; color:lightgrey">
    @Model.Count(x => x.Country == item).ToString("N0")
</span>
  • Related