开发者

ASP.NET MVC - What is the benefit of using Url.RouteUrl or Url.Action versus just using the URL directly?

What is t开发者_运维技巧he benefit of using Url.RouteUrl or Url.Action versus just using the URL directly?


If you change your routing configuration, by using Url.RouteUrl or Url.Action your generated Url's will update along with your routing configuration.

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜