I'm trying to change a route in my project, the control looks like this:
public class TagController : Controller
{
// GET: Tag
private MYEntities db = new MYEntities ();
[Route("tags")]
[OutputCache(Duration = 36000, VaryByParam = "none")]
public ActionResult Index()
{
var t = db.TAGs.OrderBy(p => p.DESCRIPTION);
return View(t.ToList());
}
}
When I run the URL:
http://localhost:7071/tags
It returns the error:
Application Server Error '/'.
Can not find resource.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could not be removed, its name changed, or is temporarily unavailable. Please review the URL and make sure which is typed correctly.
Requested URL: / tags
Version Information: Microsoft .NET Framework Version: 4.0.30319; ASP.NET Version: 04.0.30319.34248
Change:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Categoria", action = "Index", id = UrlParameter.Optional }
);
}
}
There is a Index.cshtml
view inside the Tag
folder inside the Views
folder, I believe it is not a view problem that does not exist but the route is not working.
Another thing to do is to run with:
http://localhost:7071/Tag/Index
Also the error saying that /Tag/Index
does not exist
By taking note [Route("tags")]
of method Index
it works with the URL above.
I added the following code to RouteConfig, but it did not work:
routes.MapRoute(
name: "teste",
url: "tags",
defaults: new { controller = "Tag", action = "Index", id = UrlParameter.Optional }
);
I would like to use Route[("tags")]
as shown in link