1
When creating a Controller
a :
public ActionResult Index()
{
return View();
}
But in this Controller
, if you have a new Action
if a parameter is required, if the user tries to open this link it will generate an error. Is there any way to avoid this error when 'View' is sending a parameter this way:
foreach (var item in Model)
{
<a href="/Relatorios/ListaSelecionado/@item.IDJOGOCAIXA" class="list-group-item">
Número : @Html.DisplayFor(c => item.IDJOGOCAIXA) -
</a>
}
public ActionResult ListaSelecionado(int id)
{
return View();
}
Error:
This is correct. What mistake are you making? Can you put it in your question as well?
– Leonel Sanches da Silva
This correct, plus if the user tries to open the page directly will generate an error
– Harry
Yes, but what mistake?
– Leonel Sanches da Silva
modify its
Action
forListaSelecionado(int? id)
orListaSelecionado(int id = 0)
and make appropriate treatments fornull
orzero
– Tobias Mesquita
I edited the answer.
– Leonel Sanches da Silva