0

可能重复:
如何将数据绑定到 MVC3 中 highcharts 中的折线图?

我的实体框架中有两个过程..以及将数据作为json返回的方法..我如何在我的单一方法中调用这两个过程,我必须将这两个过程作为单个json对象返回......并且在我的 jquery 中将此数据返回到我的 .$getJson 方法...任何人都可以告诉我如何执行此操作,并且返回的数据应该绑定到 highcharts 的 Linechart 作为两条单独的行可以告诉我如何实现这一点

   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应该有一行而Closedbugs应该有另一行......在这里期待帮助

4

1 回答 1

0

与 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);
}
于 2012-08-28T13:08:38.837 回答