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