1
I’m trying to pass a parameter of my view to my controller by the url and I’m not getting it, as you can see in the code below I’m using viewbag, I don’t know if it’s an error on the route or something else, if you want any other part of the code just ask:
@using (Html.BeginForm("Consultar", "Tce", FormMethod.Get, new { @id = "oForm" }))
{
<input name="pIdTce" type="text" maxlength="200" id="pIdTce" class="form-control input-sm" placeholder="Id do Tce" value="@ViewBag.IdTce">
}
@Html.ActionLink("Consultar", "Consultar", "Tce", new { id = @ViewBag.IdTce }, new { @class = "btn btn-primary btn-sm" })
Follows the controller:
using SgePrefeituraJoao.Modelo;
using System.Threading.Tasks;
using System.Web.Mvc;
using SgePrefeituraJoao.Models;
using SgePrefeituraJoao.Web.Mapeamento;
using SgePrefeituraJoao.Repositorio;
namespace SgePrefeituraJoao.Controllers
{
public class TceController : Controller
{
private readonly SgePrefeituraJoaoContext _context = new SgePrefeituraJoaoContext();
public ActionResult Tce()
{
return View("Tce");
}
[HttpGet]
public async Task<ActionResult> Consultar(int id)
{
var _TceRepositorio = new TceRepositorio();
ViewBag.pIdTce = id;
var _TCE = await _TceRepositorio.buscarTce(id);
var _TceView = MapperFacade.MapperConfiguration.Map<TceView>(_TCE);
//var _TceView = MapperFacade.MapperConfiguration.Map<TceView>(await _TceRepositorio.buscarTce(id));
return View("Consultar", _TceView);
}
}
}
How is the Tcecontroller?
– Marcelo Shiniti Uchimura
I added the controller code to the question...
– João Ignácio
The view shown above is a
~/Views/Tce/Consultar.cshtml
?– Marcelo Shiniti Uchimura