What is the benefit of using Url.RouteUrl or Url.Action versus just using the URL directly?
使用Url的好处是什么?RouteUrl或Url。是否直接使用URL ?
2 个解决方案
#1
1
If you change your routing configuration, by using Url.RouteUrl or Url.Action your generated Url's will update along with your routing configuration.
如果使用Url更改路由配置。RouteUrl或Url。操作生成的Url将与路由配置一起更新。
I find the real benefit comes when tied together with T4MVC. Then I have strongly typed access to my Action routes, so if my controller's change the compiler alerts me if any of my Url's need to change as well.
我发现真正的好处是与T4MVC绑定在一起。然后我就有了对操作路径的强类型访问,所以如果我的控制器改变了,如果我的Url需要改变,编译器就会提醒我。
#2
1
It's very simple to set up custom routing rules to create so-called "pretty" (or SEO-friendly) URLs. If you ever change one of those URLs, you don't want to have to go through your entire application and change it every time you link to that action. On the other hand, if you use Url.Action
, it will change automatically.
设置自定义路由规则来创建所谓的“漂亮”(或seo友好)url非常简单。如果你改变了其中的一个url,你就不需要遍历整个应用程序,并在每次链接到该操作时改变它。另一方面,如果您使用Url。行动,它将自动改变。
#1
1
If you change your routing configuration, by using Url.RouteUrl or Url.Action your generated Url's will update along with your routing configuration.
如果使用Url更改路由配置。RouteUrl或Url。操作生成的Url将与路由配置一起更新。
I find the real benefit comes when tied together with T4MVC. Then I have strongly typed access to my Action routes, so if my controller's change the compiler alerts me if any of my Url's need to change as well.
我发现真正的好处是与T4MVC绑定在一起。然后我就有了对操作路径的强类型访问,所以如果我的控制器改变了,如果我的Url需要改变,编译器就会提醒我。
#2
1
It's very simple to set up custom routing rules to create so-called "pretty" (or SEO-friendly) URLs. If you ever change one of those URLs, you don't want to have to go through your entire application and change it every time you link to that action. On the other hand, if you use Url.Action
, it will change automatically.
设置自定义路由规则来创建所谓的“漂亮”(或seo友好)url非常简单。如果你改变了其中的一个url,你就不需要遍历整个应用程序,并在每次链接到该操作时改变它。另一方面,如果您使用Url。行动,它将自动改变。