Hi i want to count the total number of rows in my view . I will explain my issue clearly..
My output
1) i want to count the total no of rows in the view and want to display that count in the same view of right top corner
2) I have three Customer Type New customer, Potential Customer, Existing Customer. i want to count the each type and want to display it in right top corner of the view.
I gave as like this @Model.Sum(i => i.CustomerName) but it showing error and i donno where i have to declare this line and how to calculate the Types and show in the view. please any one give
suggestion or solution for my problem.
My View
@model IEnumerable
@{
ViewBag.Title = "customerid";
}
CustomerType
Customer
| Customer Name | Customer Type |
|---|---|
@i.CustomerName | @i.CustomerType |
| Customer Name |
public class CustomerTypeViewModel
{
public System.Guid CustomerID { get; set; }
public string CustomerName { get; set; }
public DateTime CreatedDate { get; set; }
public string SalesCount { get; set; }
public string CustomerType { get; set; }
}
My controller
public ActionResult customerid()
{
List n = (from c in db.Customers where c.IsDeleted == false select c).ToList();
var customertype = string.Empty;
List obj = new List();
for (var i = 0; i < n.Count; i++)
{
var objCustomerName = n[i].DisplayName;
var objCustomerID = n[i].CustomerID;
var objCusCreatedDate = n[i].CreatedDate;
var objNextDate = objCusCreatedDate.GetValueOrDefault().AddDays(120);
var salescount = (from sc in db.SalesOrders where sc.CustomerID == objCustomerID && sc.CreatedDate >= objCusCreatedDate && sc.CreatedDate <= objNextDate select sc.SalesOrderID).Count();
if (salescount <= 3 && salescount > 0)
{
customertype = "potential Customer";
}
else if (salescount >= 3)
{
customertype = "Existing Customer";
}
else
{
customertype = "New Customer";
}
obj.Add(new CustomerTypeViewModel()
{
CustomerName = objCustomerName,
CustomerType = customertype,
SalesCount = salescount.ToString()
});
}
return View(obj);
}
Shuvojit HalderPosted Mar 29, 2016, 2:25 AM
Sneha KPosted Mar 29, 2016, 2:13 AM
Saillesh PawarPosted Mar 29, 2016, 2:11 AM
Sneha KPosted Mar 29, 2016, 2:05 AM
Saillesh PawarPosted Mar 29, 2016, 1:48 AM
Sneha KPosted Mar 29, 2016, 1:47 AM
Saillesh PawarPosted Mar 29, 2016, 1:40 AM
Sneha KPosted Mar 29, 2016, 1:36 AM
Saillesh PawarPosted Mar 29, 2016, 1:34 AM
Sneha KPosted Mar 29, 2016, 1:20 AM
Saillesh PawarPosted Mar 29, 2016, 1:16 AM