可能重复:
如何将数据绑定到MVC3中的高线图中的折线图?
我的实体框架中有两个程序。。和以json形式返回数据的方法。。如何在我的单个方法中调用这两个过程,其中我必须将这两个程序作为单个json对象返回。。。。。并将这些数据返回给我的$我的jquery中的getJson方法。。。有人能告诉我如何做到这一点吗?返回的数据应该绑定到高线图的折线图上,因为有两条单独的线可以告诉我如何实现吗
public ActionResult LoggedBugs()
{
return View();
}
public JsonResult CreatedBugs()
{
int year;
int month;
int projectid;
year=2012;
month=8;
projectid=16;
var loggedbugs = db.ExecuteStoreQuery<LoggedBugs>("LoggedBugs @Year,@Month,@ProjectID", new SqlParameter("@Year", year), new SqlParameter("@Month", month), new SqlParameter("@ProjectID", projectid)).ToList();
var ClosedBugs= db.ExecuteStoreQuery<ClosedBugs>("ClosedBugs @Year,@Month,@ProjectID", new SqlParameter("@Year", year), new SqlParameter("@Month", month), new SqlParameter("@ProjectID", projectid)).ToList();
return Json(loggedbugs, JsonRequestBehavior.AllowGet);
}
我想将loggedbugs和Closedbugs作为json对象返回到我的视图中,从那里我必须将这些数据绑定到Linechart。。。其中loggedbugs应该有一行,Closedbug应该有另一行。。。。此处需要帮助
在MVC应用程序中,与往常一样,首先定义一个视图模型,该模型将包含视图所需的信息(在您的情况下,它将是已记录和已关闭的错误的列表):
public class BugsViewModel
{
public string IEnumerable<LoggedBugs> LoggedBugs { get; set; }
public string IEnumerable<ClosedBugs> ClosedBugs { get; set; }
}
然后让您的控制器操作填充将传递给视图的视图模型:
public ActionResult CreatedBugs()
{
var year = 2012;
var month = 8;
var projectid = 16;
var loggedbugs = db.ExecuteStoreQuery<LoggedBugs>("LoggedBugs @Year,@Month,@ProjectID", new SqlParameter("@Year", year), new SqlParameter("@Month", month), new SqlParameter("@ProjectID", projectid)).ToList();
var closedBugs = db.ExecuteStoreQuery<ClosedBugs>("ClosedBugs @Year,@Month,@ProjectID", new SqlParameter("@Year", year), new SqlParameter("@Month", month), new SqlParameter("@ProjectID", projectid)).ToList();
var model = new BugsViewModel
{
LoggedBugs = loggedBugs,
ClosedBugs = closedBug
};
return Json(model, JsonRequestBehavior.AllowGet);
}