0
我想從我的視圖中的控制器中使用方法(在我的情況下爲光標)返回的結果, 以便從數據返回。 我寫了一段代碼,但我還沒有找到如何將數據傳遞給視圖。如何將控制器返回的結果從控制器傳遞到視圖
//controller
[HttpPost]
public async System.Threading.Tasks.Task<ActionResult> drawgraph(Inputmodel m)
{
List<Client> client = new List<Client>();
var collection = db.GetCollection<Client>("Client");
var builder = Builders<Client>.Filter;
var beginDate = Convert.ToDateTime(m.date_begin).Date;
var endDate = Convert.ToDateTime(m.date_end).Date;
var filter = builder.Gte("date", beginDate) & builder.Lt("date", endDate.AddDays(1)) & builder.Eq("field2", m.taux);
var cursor = await collection.DistinctAsync<double>("field2",filter);
return View(cursor);
}
//view
@{
var myChart = new Chart(width:600,height: 400)
.AddTitle("graphique")
.AddSeries(chartType: "Line")
.DataBindTable(dataSource: cursor, xField: "date", yField:"field2") //here I want to use the returnet result by drawgraph in the controller
.Write();
}
您需要創建一個模型,將數據傳遞給它,然後在視圖中使用該模型。 – Kami