0
I created a new Controller with name 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
) for this new View(Conteudo
) and when I give a View in browser, it gives Page not found(404) error. In the Url it looks like this: .. /Content/Content.
My route is like this:
routes.MapRoute(
name: "RotaConteudo",
url: "Conteudo/{Parametro}/{tipo}",
defaults: new { controller = "Conteudo", action = "Conteudo", Parametro = "", tipo = "" }
);
Okay, here’s the deal. I created a new view and a new controller. Inside the controller, I created an action(Actionresult). I created a new view and pointed to this controller. This Action, receives two parameters, as I did in Route. What happens is that nothing is working. There is no error, but it also does not work. Trying to solve now, I changed the parameters from int to string, I did view in browser and this way I was able to view the view. But not by the app. I put a break in Action and it doesn’t stop. It doesn’t do anything and it doesn’t work. In other words, my controller isn’t 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) {
}
});
}
Your question is very confusing, you can improve it?
– Ricardo
Okay, here’s the deal. I created a new view and a new controller. Inside the controller, I created an action(Actionresult). I created a new view and pointed to this controller. This Action, receives two parameters, as I did in Route. What happens is that nothing is working. There is no error, but it also does not work. Trying to solve now, I changed the parameters from int to string, I did view in browser and this way I was able to view the view. But not by the app. I put a break in Action and it doesn’t stop. It doesn’t do anything and it doesn’t work.
– pnet
Update on your question.
– Ricardo
I posted my action and my js function, to see if there is anything missing. In my cshtml(View), I pointed to js Conteudo.js.
– pnet
I think my problem is this, after thinking a lot. I have an Index that assembles the menu. In this menu I must call the Content, passing the proper parameters, to get the correct HTML of the BD. In the index I also point to Conteudo.js. I’m not able to move the menu up by passing the route. I put a break in both Controller and . js and can’t debug, not break. I can’t be too clear in my doubt, for lack of understanding of the whole thing.
– pnet
What did you mean by the route you would take, in this part ? { parametro = "", type = "" }
– Raffa Ferreira