MVC5中不同年龄段的数据收集 [英] Data collection between ages in mvc5
本文介绍了MVC5中不同年龄段的数据收集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
**我曾经尝试收集不同年龄段的数据,但有一个错误,我不知道为什么这是我的控制器代码 **
**hi gays I have tried to collect data between ages but there is an error I do not know why here is my code my controller **
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>
我找不到问题,您能帮我吗
我的控制器中的问题在这里在此处输入图像描述
the problem in my controller here enter image description here
推荐答案
jmal hassn
jmal hassn
公共IEnumerable Count {get;放; }
public IEnumerable Count { get; set; }
但是您传递的Count本身就是一个整数
But you are passing Count which is an int by itself
选择新的UserRange {AgeRange = g.Key,Count = g.Count()}
select new UserRange { AgeRange = g.Key, Count = g.Count() }
您必须传递一个pations列表,然后您就可以依靠它了
You have to pass a list of pations and than you count on that
这篇关于MVC5中不同年龄段的数据收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文