I have MVC website where i am trying to make absolute URL with url.action but not succeed yet.
Here is code i am using:
<li><a href="@Url.Action("Index", "Home")">Home</a></li>
<li><a href="@Url.Action("Contact","Home")">Contact</a></li>
Both Home and Contact are in same View.
So here is the error description: When I run the website it shows this url and open website perfectly. Now if I click on "Contact" link it shows correct URL:
http://localhost:5423/Home/Contact
After that I am clicking on "Home" Link it gives me wrong URL:
http://localhost:5423/Home/Home/Index
Correct Url should be this:
http://localhost:5423/Home/Index
I don't know why its retaining "Home" in URL.
This is what I wrote in Global.asax.vb
Public Class MvcApplication
Inherits System.Web.HttpApplication
Sub Application_Start()
AreaRegistration.RegisterAllAreas()
WebApiConfig.Register(GlobalConfiguration.Configuration)
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters)
RouteConfig.RegisterRoutes(RouteTable.Routes)
BundleConfig.RegisterBundles(BundleTable.Bundles)
AuthConfig.RegisterAuth()
End Sub
End Class
Here is the code for RouteConfig:
Public Class RouteConfig
Public Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
routes.IgnoreRoute("{resource}.axd/{*pathInfo}")
routes.MapRoute( _
name:="Default", _
url:="{controller}/{action}/{id}", _
defaults:=New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional} _
)
End Sub
End Class
This is only the problem I am facing.
Please give your views and suggestions.