我MVC网站,我想使绝对URL与url.action但没有成功呢。
I have MVC website where i am trying to make absolute URL with url.action but not succeed yet.
下面是code,我使用:
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:
localhost:5423/Home/Contact之后,我点击首页链接它给了我错了网址:
After that I am clicking on "Home" Link it gives me wrong URL:
localhost:5423/Home/Home/Index正确的URL应该是这样的:
Correct Url should be this:
localhost:5423/Home/Index我不知道为什么它的固定家的网址。
I don't know why its retaining "Home" in URL.
这是我在写Global.asax.vb
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下面是code为RouteConfig:
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.
请给你的意见和建议。
推荐答案右键,我想我是针对错误的事情。在你的 RouteConfig.cs 文件, Right, I think I was targeting the wrong thing. In your RouteConfig.cs file, ad new routes for Home/Index and Home/Contact (apologies for the C#, I don't use VB.NET anymore): 在你看来,创建这样的链接: In your view, create the links like this: 这样做应该可以解决您的网址的问题。为什么首页正在出现两次,我不清楚,但创建自己的路线应该有所帮助。 Doing this should fix your url issue. Why Home is appearing twice is unclear to me, but creating your own routes should help.
更多推荐
不能产生与在MVC @ Url.Action绝对URL
发布评论