0

重複の可能性:
MVC3 のハイチャートでデータを折れ線グラフにバインドする方法は?

エンティティ フレームワークに 2 つのプロシージャがあり、データを json として返すメソッドがあります。これら 2 つのプロシージャを単一のメソッドで呼び出すにはどうすればよいですか。これらの 2 つのプロシージャを単一の 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 には 1 つの行があり、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 に答える