I created a new Controller named Conteudo
. Then I created an Action on it called conteudo
and added a new View called Conteudo
. Before it was PaginaBase
and the Controller of Home
. Well, I copied the contents of the old View ( PaginaBase
) to this new View ( Conteudo
) and when I give a View in browser, it gives Page not found error (404). In Url it looks like this: ../Conteudo/Conteudo.
My route looks like this:
routes.MapRoute(
name: "RotaConteudo",
url: "Conteudo/{Parametro}/{tipo}",
defaults: new { controller = "Conteudo", action = "Conteudo", Parametro = "", tipo = "" }
);
Ok, this is the next. I created a new view and a new controller. Inside the controller, I created an action (ActionResult). I created a new view and pointed it to this controller. This Action, receives two parameters, as I did on the Route. What happens is that nothing is working. It does not make a mistake, but it does not work either. Trying to solve now, I changed the parameters from int to string, with right done view in browser and this way I was able to view the view. But by application not. I put a break on Action and it does not stop. It does nothing and does not work. That is, my controller is not working.
My action:
public ActionResult Conteudo(string nome, int Parametro, int tipo)
{
AgaxturCmsEntities db = new AgaxturCmsEntities();
int _parametro = Parametro;
try
{
switch (tipo)
{
case 1:
{
var resultado = (from i in db.TB_INSTITUCIONAL
join c in db.TB_INSTITUCIONAL_CATEGORIAS on i.Id_Categoria equals (c.id)
where i.Ativo == 1 && c.Ativo == 1 && c.CdCliente == 1 && i.Id_Categoria == _parametro
select new
{
Conteudo = i.Conteudo
}).FirstOrDefault();
ViewData["htmlBase"] = resultado.Conteudo;
break;
}
case 2:
{
var menu_sup = (from rc in db.TB_MENUSUPERIOR
join c in db.TB_MENUSUPERIOR_CATEGORIAS on rc.Id_Categoria equals (c.id)
//join s in db.TB_MENUSUPERIOR_SUBCATEGORIAS on rc.Id_SubCategoria equals (s.id)
//join s2 in db.TB_MENUSUPERIOR_SUBCATEGORIAS2 on rc.Id_SubCategoria2 equals (s2.id)
where rc.Ativo == 1 && rc.Cdcliente == 1 && rc.Id_Categoria == _parametro
select new
{
Conteudo = rc.Conteudo
}).FirstOrDefault();
ViewData["htmlBase"] = menu_sup.Conteudo;
break;
}
case 3:
{
var menu_sup = (from rc in db.TB_MENUSUPERIOR
join s in db.TB_MENUSUPERIOR_SUBCATEGORIAS on rc.Id_SubCategoria equals (s.id)
join s2 in db.TB_MENUSUPERIOR_SUBCATEGORIAS2 on rc.Id_SubCategoria2 equals (s2.id)
where rc.Ativo == 1 && rc.Cdcliente == 1 && rc.Id_SubCategoria2 == _parametro
select new
{
Conteudo = rc.Conteudo
}).FirstOrDefault();
ViewData["htmlBase"] = menu_sup.Conteudo;
break;
}
}
return View("Conteudo");
}
catch (Exception ex)
{
string e = ex.Message;
}
return View();
}
My jquery
function MontaMenuInferior() {
var str = "";
$.ajax({
url: '/Conteudo/MontaMenuInferior',
dataType: "json",
contentType: "application/json; charset=utf-8",
type: "POST",
success: function (data) {
$(data.resultado).each(function () {
str = str + '<ul class="grid_4">' +
'<li>' + this.SubCategoria + '</li>';
$(this.subconsulta).each(function () {
if (this.Id_SubCategoria2 != null)
str = str + '<li><a href="/Conteudo/' + 'teste-de-nome/' + this.Id_SubCategoria2 + '/3" title="">' + this.SubCategoria2 + '</a></li>';
//str = str + '<li><a href="@Url.RouteUrl("PaginaBase",new{ Parametro = 6, tipo = 3} )">' + this.SubCategoria2 + '</a></li>'
else
str = str + '<li><a href="#' + this.SubCategoria2 + '" title="">' + this.SubCategoria2 + '</a></li>';
});
str = str + '</ul>';
$('#menufooter').append(str);
str = "";
});
},
error: function (error) {
}
});
}