2
我需要在图表上显示这两个查询的数据。我可以一次一个条形图地显示数据。但我想一起显示在同一页面上。使用一个模型发送两个LINQ查询以查看
public ActionResult Daily(string label)
{
var DataContext = new BalanceDataContext();
var month = label.Split('-')[0];
var year = label.Split('-')[1];
//Percentage of Estimated Electric Bills
var rdcd = new string[] { "CE", "IE" };
var totalEstimated = (from a in DataContext.pujhaccds
join b in DataContext.pujhmtrds
on a.billnumber equals b.billnumber
where year.Equals(a.billdate.Value.Year)
&& month.Equals(a.billdate.Value.Month)
&& rdcd.Contains(b.reading_code)
group a by new {a.billdate.Value.Day} into p
orderby p.Key.Day ascending
select new Date1() { theDay2 = p.Key.Day, theCount2 = p.Count() });
var totalday = (from m in DataContext.pujhaccds
where month.Equals(m.billdate.Value.Month) &&
year.Equals(m.billdate.Value.Year)
group m by new { m.billdate.Value.Day } into p
orderby p.Key.Day ascending
select new Date1() { theDay = p.Key.Day, theCount = p.Count() });
int monthInt = 0;
Int32.TryParse(month, out monthInt);
string strMonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(monthInt);
ViewBag.Message = "Bills for: " + strMonthName + year;
return View(new QueryView { Date2 = totalEstimated, Date1 = totalday.ToArray() });
}
这里是模型的样子:
public class Date1
{
public string Month { get; set; }
public string Year { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime? DateStart { get; set; }
public DateTime? DateEnd { get; set; }
public int theDay { get; set; }
public int theDay2 { get; set; }
public string theString { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:MMMM-yyyy}", ApplyFormatInEditMode = true)]
public DateTime? theDate { get; set; }
public int theCount { get; set; }
public int theCount2 { get; set; }
}
我试图创建另一种模式来保存数据,但它似乎没有工作
public class QueryView
{
public IEnumerable<Date1> Date1 { get; set; }
public IEnumerable<Date1> Date2 { get; set; }
}
我有这在我看来最重要的,没有错误信息:
@model CWebPortal.Models.QueryView
当我有这个,我得到了错误:
@model IEnumerable<CWebPortal.Models.QueryView>
这工作,但仅限于从控制器的一个查询:
@model IEnumerable<CWebPortal.Models.Date1>
这是我如何抓住数据在图表查看:
jQuery(function ($) {
$.jqplot.config.enablePlugins = true;
var items = @Html.Raw(Json.Encode(Model));
var ticks = [];
var s1 = [];
var s2 = [];
for (var i = 0; i < items.length; i++) {
ticks.push(items[i].theDay);
s1.push(items[i].theCount);
}
如何将两个查询都放到我的视图中?