asp.net-mvc-4 - 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>
我的控制器中的问题在此处输入图像描述
解决方案
杰马尔·哈森
公共 IEnumerable 计数 { 获取;放; }
但是您传递的 Count 本身就是一个 int
选择新用户范围 { AgeRange = g.Key, Count = g.Count() }
你必须通过一个列表,而不是指望那个
推荐阅读
- angular - Ionic 4 编译失败(角度 6)
- python - 如何使用 plotly 在气泡图上添加文本
- android - 平板电脑中的多桌面 (Android)
- android - 在android中调用videoview.seekTo()时无法播放视频流
- python - 无法设置字体大小和 rtl
- matlab - 使用 KNN 在 2D 中减小矩阵大小
- sql - 用分层数据类型查询表的更有效的 T-SQL 方法是什么
- c - 多项式操作
- asp.net - 为什么 DateTime.Now.TimeOfDay 不能作为手动时间设置?
- loops - 将现有文件分成多个文件,分别包含特定字段