i'm new in Asp Net and i have some questions. So i make an example to understand, this example return a tempData with the match name in the List. The List has 3 objects created in the actionResult Index.
[HttpPost]
public ActionResult Buscar(String NomeP)
{
int i;
List<Models.Produto> Lista = null;
Lista = Session["SSLista"] != null ? (Session["SSLista"] as List<Models.Produto>) : new List<Models.Produto>();
for (i = 0; i< Lista.Count; i++) {
if (Lista[i].Nome.Equals(NomeP)) {
TempData["Found"] = Lista[i];
}
}
return RedirectToAction("Produto", "Home");
}
When i try to show the return i receive this exception of NUllReference, but the tempData has some data in return.
<% Html.EndForm(); %> <%
if (TempData["Found"] != null)
{ %>
<%
foreach (var prod in (TempData["Found"] as List<MvcApplication2.Models.Produto>))
{
%>
<br />
<h2>Produtos</h2>
<label>
Nome: <%=prod.Nome %>
</label>
<label>
Descrição <%= prod.Descricao%>
</label>
<label>
Preço: <%= prod.Valor_unitario%>
</label>
<label>
ID: <%= prod.Id%>
</label><br>
<% }
}
The image below show's that Tempdata has some Data, but i can convert in the foreach.