mvc5中年龄之间的数据收集
Data collection between ages in mvc5
我尝试收集不同年龄段的数据,但出现错误我不知道为什么这是我的代码我的控制器
public ActionResult AllCuont()
{
var query = (from t in db.Pations
let range = (
t.Age >= 0 && t.Age < 10 ? "0-9" :
t.Age >= 11 && t.Age < 15 ? "10-14" :
t.Age >= 15 && t.Age < 50 ? "15-50" :
"50+"
)
group t by range into g
select new UserRange { AgeRange = g.Key, Count = g.Count() }).ToList();
//add the sum column.
query.Add(new UserRange() { AgeRange = "Sum", Count = query.Sum(c => c.Count) });
ViewBag.UserData = query;
return View();
}
这是我收集价值的模型
namespace Archive.Models
{
public class UserRange
{
public string AgeRange { get; set; }
public IEnumerable<Pation> Count { get; set; }
}
}
这是我的观点
<table border="1">
<tr>
@foreach (var item in ViewBag.UserData)
{
<th>@item.AgeRange </th>
}
</tr>
<tr>
@foreach (var item in ViewBag.UserData)
{
<td>@item.Count </td>
}
</tr>
这里是我控制器的问题enter image description here
jmal hassn
public IEnumerable Count { get; set; }
但是你传递的是 Count,它本身就是一个整数
select new UserRange { AgeRange = g.Key, Count = g.Count() }
你必须通过一系列的治疗,而不是你指望的
我尝试收集不同年龄段的数据,但出现错误我不知道为什么这是我的代码我的控制器
public ActionResult AllCuont()
{
var query = (from t in db.Pations
let range = (
t.Age >= 0 && t.Age < 10 ? "0-9" :
t.Age >= 11 && t.Age < 15 ? "10-14" :
t.Age >= 15 && t.Age < 50 ? "15-50" :
"50+"
)
group t by range into g
select new UserRange { AgeRange = g.Key, Count = g.Count() }).ToList();
//add the sum column.
query.Add(new UserRange() { AgeRange = "Sum", Count = query.Sum(c => c.Count) });
ViewBag.UserData = query;
return View();
}
这是我收集价值的模型
namespace Archive.Models
{
public class UserRange
{
public string AgeRange { get; set; }
public IEnumerable<Pation> Count { get; set; }
}
}
这是我的观点
<table border="1">
<tr>
@foreach (var item in ViewBag.UserData)
{
<th>@item.AgeRange </th>
}
</tr>
<tr>
@foreach (var item in ViewBag.UserData)
{
<td>@item.Count </td>
}
</tr>
这里是我控制器的问题enter image description here
jmal hassn
public IEnumerable Count { get; set; }
但是你传递的是 Count,它本身就是一个整数
select new UserRange { AgeRange = g.Key, Count = g.Count() }
你必须通过一系列的治疗,而不是你指望的