From the answers here, I could not get it. I have this view
@{
ViewBag.Title = "ExcelFinancing";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta name="viewport" content="width=device-width" />
<title></title>
<style>
.embaixo {
position: absolute;
left: 0;
bottom: 20%;
width: auto;
bottom: auto;
top: 50%;
margin: 10%,10%,10%,10%;
}
</style>
</head>
<body>
<div class="row">
<div class="col-lg-12">
<h3 class="page-header fa-align-center">@ViewBag.TitlePage</h3>
</div>
</div>
@*<div class="panel panel-default">*@
<div class="form-group">
<div class="col-md-1">
@Html.Label("De")
</div>
<div class="col-md-3">
@Html.EditorFor(model => model.datefinancing, new { htmlAttributes = new { @class = "form-control", ID = "dataIni" } })
@Html.ValidationMessageFor(model => model.datefinancing, "", new { @class = "text-danger" })
</div>
<div class="col-md-1">
@Html.Label("Até")
</div>
<div class="col-md-3">
@Html.EditorFor(model => model.datefinancing, new { htmlAttributes = new { @class = "form-control", ID = "dataFim" } })
@Html.ValidationMessageFor(model => model.datefinancing, "", new { @class = "text-danger" })
</div>
</div>
<div class="row">
<div class="input-field col s3">
<div>
<p>
@{string Todos = ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldId("Todos");}
@Html.RadioButtonFor(model => model.statussolicitation, "Todos", new { id = Todos, name = "imp_tx_tipo", value = "Todos", @class = "with-gap" })
<label for="Todos">Todos</label>
</p>
<p>
@{string Ativos = ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldId("Ativos");}
@Html.RadioButtonFor(model => model.statussolicitation, "Ativos", new { id = Ativos, name = "imp_tx_tipo", value = "Ativos", @class = "with-gap" })
<label for="Ativos">Ativos</label>
</p>
<p>
@{string Inativos = ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldId("Inativos");}
@Html.RadioButtonFor(model => model.statussolicitation, "Inativos", new { id = Inativos, name = "imp_tx_tipo", value = "Ativos", @class = "with-gap" })
<label for="Inativos">Inativos</label>
</p>
@Html.ValidationMessageFor(model => model.statussolicitation, "", new { @class = "red-text text-darken-2" })
</div>
</div>
</div>
@using (Html.BeginForm("geraExcel1", "FinancingReport", FormMethod.Post))
{
<div class="input-group">
<div class="input-group-btn">
<input type="submit" value="Gerar Relatório" class="btn btn-primary" />
</div>
</div>
}
</body>
</html>
This is my controller
[HttpPost]
public ActionResult geraExcel1()
{
var context = new SyngentaBenefitsEntities();
var model = new SolicitationViewModel();
//var teste = dataFim;
geraExcel();
ViewBag.TitlePage = "Relatório de Financiamento";
return null;
}
[HttpPost]
public ActionResult geraExcel()
{
List<vwFinancingReportViewModel> lista = new List<vwFinancingReportViewModel>();
lista = dadosPlanilha();
StringBuilder sb = new StringBuilder();
sb.Append("Status;Nro.Pessoal;Nome Completo;Grade;Nro.Solicitação;Data Financiamento;" +
"Ano Fabric.;Modelo;Chassi;Valor Bem;Valor Financiado;Status Solicitação;Status Pagamento;" +
"Valor Parcela;Juros;ReembolsoKM;Reembolso Depreciação\r\n");
foreach(var item in lista)
{
sb.Append(item.employeestatus.ToString() + ";" + item.employeeid.ToString() + ";" + item.fullname.ToString() + ";" +
item.grade.ToString() + ";" + item.solicitationid.ToString() + ";" + item.datefinancing.ToString() + ";" +
item.manufacturer.ToString() + ";" + item.model.ToString() + ";" + item.chassi.ToString() + ";" +
item.valueproperty.ToString() + ";" + item.valuegranted.ToString() + ";" + item.statussolicitation.ToString() + ";" +
item.paymentstatus.ToString() + ";" + item.valuepayment.ToString() + ";" +
item.valueinterest.ToString() + ";" + item.refundkm.ToString() + ";" +
item.refund.ToString() + "\r\n");
}
//sb.Append("Eduardo;11111\r\n");
//sb.Append("Coutinho;22222\r\n");
HttpContext.Response.Clear();
HttpContext.Response.AddHeader("content-disposition", string.Format("attachment;filename=" + DateTime.Now.ToString("yyyyMMdd") + "ReportFinanciamentoRH.csv"));
HttpContext.Response.ContentType = "application/CSV";
HttpContext.Response.ContentEncoding = System.Text.Encoding.Default;
HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Response.Write(sb.ToString());
HttpContext.Response.End();
return null;
}
In the view I have a DateTime field, where would be a filter for my sql, which would be StartDate and EndDate. It turns out that I'm not sure how to send these values to the controller, so I can use them in my query.