0
I know the error is in the way I am 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 such. Well, I tried several ways and I know one 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 the Download button is
<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>
The way it is, that’s the mistake you’re making:
Server Error in Application '/'.
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 'Report.Controllers.Appealreportcontroller'. An optional Parameter must be a Reference type, a nullable type, or be declared as an optional Parameter. Parameter name: Parameters
Description: An untreated exception occurred during the execution of current web request. Examine stack tracking to get more information about the error and where it originated in the code.
Exception Details: System.Argumentexception: 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 'Report.Controllers.Appealreportcontroller'. An optional Parameter must be a Reference type, a nullable type, or be declared as an optional Parameter. Parameter name: Parameters
Error of Origin:
Untreated exception was generated during the current execution web request. The information related to the origin and location of the exception can be identified by using stack tracking exception below.
Cell Trace:
What’s wrong in the post to receive the downvote?
– pnet