Wednesday, June 8, 2016

ASP.Net MVC Multiple submit buttons on a Form

// Form markup
<input name="submit" type="submit" value="Download" class="btn btn-primary" />
<input name="submit" type="submit" value="Display" class="btn btn-primary" />

// Controller processor
public ActionResult SomeReport(SomeModel model,string submit)
{
if (submit == "Display")
{
return View(model);
}
else if (submit == "Download")
{
return DownloadReport(model);
}
}

ActionResult DownloadRevenueReport(RevenueReportListModel model)
{
return File(Encoding.UTF8.GetBytes(GetTextData(model)),
"application/text", "Report.csv");
}