Hardcoding the urls its a fake solution. You should use Html.ActionLink and make sure you have the routes defined correctly.
Agreed. Hardcoding a url like that will only cause more problems down the road making it harder to maintain and track down bugs. You need to set up a custom route (it's not difficult for what you want).
Here is how you can add the behavior you want while using an action link (which again is preferred).
//Keep the link as
<li>@Html.ActionLink("FootballClub", "FootballClub", "home")</li>
//In the global.asax file add the following route to the route table
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"FootballClub",
"FootballClub",
new { controller = "Home", action = "FootballClub"" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
inkey
Member
89 Points
109 Posts
Simple Html.ActionLink query
Mar 27, 2012 08:43 AM|LINK
I have the following ActionLink and when i click on the button it is only redirecting to /home/FootballClub
<li>@Html.ActionLink("FootballClub", "FootballClub", "home")</li>
I need to have the above redirecting to /Footballclub instead how would i go about changing this.
I am new to asp.net MVC
Thanks
inkey
Member
89 Points
109 Posts
Re: Simple Html.ActionLink query
Mar 27, 2012 09:30 AM|LINK
Found the answer myelf
<a href="/App/DoAbout">About this application</a>
raduenuca
All-Star
24675 Points
4250 Posts
Re: Simple Html.ActionLink query
Mar 27, 2012 09:47 AM|LINK
Hardcoding the urls its a fake solution. You should use Html.ActionLink and make sure you have the routes defined correctly.
Radu Enuca | Blog
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Simple Html.ActionLink query
Mar 27, 2012 03:40 PM|LINK
Agreed. Hardcoding a url like that will only cause more problems down the road making it harder to maintain and track down bugs. You need to set up a custom route (it's not difficult for what you want).
Routing Tutorial:
http://www.asp.net/mvc/tutorials/older-versions/controllers-and-routing/asp-net-mvc-routing-overview-cs
Here is how you can add the behavior you want while using an action link (which again is preferred).
//Keep the link as <li>@Html.ActionLink("FootballClub", "FootballClub", "home")</li> //In the global.asax file add the following route to the route table public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "FootballClub", "FootballClub", new { controller = "Home", action = "FootballClub"" } ); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults ); }Blog | Twitter : @Hattan