我在這裏遇到了問題,我希望有人能幫助我解決我的問題。問題是:即時通訊使用C#和MVC。我想將db表傳遞給另一個函數。我不知道如何解決這個..希望有人在那裏可以幫助我將查詢表傳遞給mvc中的另一個函數c#
public ActionResult Index()
{
var viewModel = db.test.ToList()
ExportExcel(viewModel); //pass current table to excel to export
return View(viewModel);
}
//export to excel
public ActionResult ExportExcel(xxxx viewModel)
{
var grid = new GridView();
grid.DataSource = from p in viewModel
select new
{
Name = p.name,
No = p.staffno
};
grid.DataBind();
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");
Response.ContentType = "application/ms-excel";
Response.Charset = "";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
grid.RenderControl(htw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
return View("MyView");
}
究竟有什麼問題了嗎?什麼不起作用? –
我想將索引()中的viewModel傳遞給ExportExcel()..但我不知道如何調用它..請參閱ExportExcel'xxxx' – achimet
將xxxx更改爲'viewModel'的類型? – Shyju