I am in the process of generating a URL dynamically in my cshtml page.
What is the difference between Url.RouteUrl() & Url.Action()?
Which one should I use to generate the URL & what difference do both have in terms of implementation ?
Thanks in advance.
RouteUrlgenerated the url based on route name. If you have multiple routes with similar parameters theActionmethod may pick a wrong one – it works based on the order of route definitions. This may take place when your routes have optional parameters.If you want to make sure that a certain route url will be used you need to call
RouteUrlpassing this route name. Route names are unique and clearly identifies a route.One more difference is that
Actionis MVC specific (it uses controller and action names), whileRouteUrlis generic is and can be used without MVC (you can have routing in WebForms).