0
Guys, I need you to help me figure out where I’m going wrong and how to fix a little problem. I don’t know much about MVC, but I’m turning around here.
I need to pass a Model class as a parameter to an Actionresult, but the variable is being sent empty.
My Index()
@model IEnumerable<Sistemas.Digital.Model.PoderesPJ.Poder>
@{
ViewBag.Title = "Poderes";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@*@using (Html.BeginForm())
{
*@<fieldset>
<legend></legend>
<h2>Poderes</h2>
<table class="table">
<thead>
<tr>
<th>@Html.DisplayNameFor(model => model.Nome)</th>
<th>@Html.DisplayNameFor(model => model.Codigo)</th>
<th>@Html.DisplayNameFor(model => model.Inicio)</th>
<th>@Html.DisplayNameFor(model => model.Vencimento)</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.Nome)</td>
<td>@Html.DisplayFor(modelItem => item.Codigo)</td>
<td>@Html.DisplayFor(modelItem => item.Inicio)</td>
<td>@Html.DisplayFor(modelItem => item.Vencimento)</td>
<td>@Html.ActionLink("Detalhes", "Detalhes", new { item = item.Detalhes })</td>
</tr>
}
</tbody>
</table>
</fieldset>
My Method in Controller
public ActionResult Detalhes(PoderesPJ.Detalhes item)
{
return View(item);
}
The problem I believe is in Actionlink, which does not send the filled Class.
Controller Completo
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Sistemas.Digital.Model;
using Sistemas.Digital.GERAL;
using Util.Crawler;
namespace Aplicativos.CockPit.Controllers
{
public class PoderController : Controller
{
//
// GET: /Poder/
List<PoderesPJ.Poder> listaPoder;
Crawler cr = new Crawler();
private List<PoderesPJ.Poder> ListaPoderes(string agencia, string conta, ref Crawler cr)
{
List<PoderesPJ.Poder> _poderes = new List<PoderesPJ.Poder>();
ConsultaPoderesPJ consulta = new ConsultaPoderesPJ();
_poderes = consulta.ConsultaPoderesAgenciaConta(ref cr, agencia, conta);
return _poderes.OrderBy(d => d.Nome).ToList();
}
public ActionResult Index()
{
string _param1 = "1234";
string _param2 = "456789";
listaPoder = ListaPoderes(param1, param2, ref cr);
return View(listaPoder);
}
public ActionResult Detalhes(PoderesPJ.Detalhes item)
{
return View();
}
}
}
Post your Action Index code
– Pablo Tondolo de Vargas
Includes the full Controller
– Luiz Martinez
Luiz, I’m gonna need to see your consult
– Pablo Tondolo de Vargas
In the
Detalhes
, not missing to put the item in the Return.return View(item);
– Pablo Tondolo de Vargas