I know the error is in the way I'm interpreting the routine. I have a routine to download a file attached to a table. This file was generated by my application (binary) and now I need to write this binary in any dir, that is, in my table / grid there are several files and I need to write the ID file as such. Well, I tried several ways and I know a detail I'm not getting. Here's what I've done: CONTROLLER:
public FileResult Download(int id)
{
int _arquivoId = id;
var arquivos = oModelFiles.GetFileReport(id);
string nomeArquivo = (from arquivo in arquivos
where arquivo.ID_SOLIC_RELATORIO == _arquivoId
select arquivo.BL_RELATORIO).First().ToString();//iSSO AQUI É TENTATIVA.
string contentType = "application/pdf";
return File(nomeArquivo, contentType, "report.pdf");
}
My class to get the file
public class ModelFiles
{
public List<POC_SOLIC_RELATORIO> GetFileReport(int _Id_Solic_Relat)
{
List<POC_SOLIC_RELATORIO> lstFiles = new List<POC_SOLIC_RELATORIO>();
//DirectoryInfo dirInfo = new DirectoryInfo(HostingEnvironment.MapPath("~/Arquivos"));
DirectoryInfo dirInfo = new DirectoryInfo("C:/Relatemp/");
string arquivoCaminho = string.Empty;
int i = 0;
foreach (var item in dirInfo.GetFiles())
{
lstFiles.Add(new POC_SOLIC_RELATORIO()
{
ID_RELATORIO = _Id_Solic_Relat,
//arquivoID = i + 1,
//arquivoNome = item.Name,
//FilePath = dirInfo.FullName + @"\" + item.Name
});
i = i + 1;
}
return lstFiles;
}
}
My view where you have the Download button
<table class="table">
<tr>
<th>
@*@Html.DisplayNameFor(model => model.POC_RELATORIO.NM_RELATORIO)*@
@Html.DisplayName("Nome do Relatório")
</th>
<th>
@Html.DisplayName("Relatório")
</th>
<th>
@*@Html.DisplayNameFor(model => model.ID_USUARIO)*@
@Html.DisplayName("Usuário")
</th>
<th>
@*@Html.DisplayNameFor(model => model.DT_SOLICITACAO)*@
@Html.DisplayName("Data da Solicitação")
</th>
<th>
@*@Html.DisplayNameFor(model => model.DT_AGENDAMENTO)*@
@Html.DisplayName("Data do Agendamento")
</th>
<th>
@*@Html.DisplayNameFor(model => model.DT_GERACAO)*@
@Html.DisplayName("Data da Geração do Relatório")
</th>
<th>
@*@Html.DisplayNameFor(model => model.BL_RELATORIO)*@
@Html.DisplayName("Relatório")
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.POC_RELATORIO.NM_RELATORIO)
</td>
<td>
@Html.DisplayFor(modelItem => item.ID_SOLIC_RELATORIO)
</td>
<td>
@Html.DisplayFor(modelItem => item.ID_USUARIO)
</td>
<td>
@Html.DisplayFor(modelItem => item.DT_SOLICITACAO)
</td>
<td>
@Html.DisplayFor(modelItem => item.DT_AGENDAMENTO)
</td>
<td>
@Html.DisplayFor(modelItem => item.DT_GERACAO)
</td>
<td>
@Html.DisplayFor(modelItem => item.BL_RELATORIO)
</td>
<td>
@Html.ActionLink("Download", "Download", new { item.ID_SOLIC_RELATORIO, item.BL_RELATORIO })
</td>
<td>
@Html.ActionLink("Open", "", "")
</td>
@*<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ID_SOLIC_RELATORIO }) |
@Html.ActionLink("Details", "Details", new { id=item.ID_SOLIC_RELATORIO }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ID_SOLIC_RELATORIO })
</td>*@
</tr>
}
</table>
As it is, this is the error you are giving:
Application Server Error '/'.
The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.FileResult Download (Int32) 'in' Relatorio.Controllers.AppealReportController '. An optional parameter must be a reference type, nullable type, or be declared as an optional parameter. Parameter name: parameters
Description: An unhandled exception occurred during the execution of the current Web request. Examine the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: The parameters dictionary contains null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.FileResult Download (Int32) 'in' Relatorio.Controllers.AppealReportController '. An optional parameter must be a reference type, nullable type, or be declared as an optional parameter. Parameter name: parameters
Source Error:
Unhandled exception was generated during the execution of the current information. The information relating to the origin and location of the can be identified using the stack trace of exception below.
Battery Tracking: