Can I make ASP.NET MVC Html.RouteLink () return the URL of my homepage without an ID?

I have one route on my page Global.asax.vbsimilar to this ...

Shared Sub RegisterRoutes (ByVal routes As RouteCollection)
    routes.IgnoreRoute ("{resource} .axd / {* pathInfo}")
    routes.MapRoute (_
        "IdOnly", _
        "{id}", _
        New With {.controller = "Page", _
                  .action = "Details", _
                  .id = "7"} _
    )
End sub

This is idfor my homepage. It is displayed when someone goes to mine:http://example.com/

But this also works: http://example.com/7

I would like my site to not have links with an address idof 7. But the function Html.RouteLink()generates these.

Model, & hellip;

<%=Html.RouteLink(Model.Parent.Title, _
                  "IdOnly", _
                  New With {.id = Model.Parent.Id})%>

& hellip; :

<a href="/7">Home</a>

href, Html.RouteLink() ?

+3
1

"IdOnly" :

routes.MapRoute( _
    "HomePage", _
    "", _
    New With {.controller = "Page", _
              .action = "Details", _
              .id = "7"} _
)

RouteLink .

+4

Source: https://habr.com/ru/post/1704987/


All Articles