cheny
cheny

Reputation: 2735

What's the benefits of asp.net MVC routing?

Rather than "/MyController/Index?teamId=3&type=4", MVC routing prefers :"/MyController/3/4". So what's the benefits of doing so? On the contrary, I am suffering many drawbacks of it. For example:

  1. Not readable for people.

What's 3 and 4?

  1. If I store them somewhere (for test cases, etc), different links may point to same pages.

"Have you tested /MyController/3/4?""no, but I've tested /MyController/Index/3/4""..."

  1. Difficult to be analyzed by JavaScript.

I have some js codes to make "current link" black text. For example, if a link on the page (usually a menu item) links to the page itself, the link will be changed to black text. But in this case, the link "/MyController/3/4" on page "/MyController/Index/3/4" cannot be processed properly.

So why should we use MVC routing like that? And how should I overcome the 3rd problem listed above? That's why I'm here :)

Thanks for any hint.

Upvotes: 0

Views: 364

Answers (2)

Brad C
Brad C

Reputation: 2982

  1. You would be much better off with routing using actual string names instead of IDs where you can get away with it... such as /Teams/TeamNameOrAbbreviation/TeamType

  2. Different links pointing to the same pages stems from the defaults set in the routeconfig. If you do not want this to happen, you can change how you are handling your defaults.

  3. You can process the links properly if you use MVC's built in methods to do so. You can resolve URLs using helpers such as @Url.Action() for comparison and usage in js code since it always generates the same one every time.

Upvotes: 1

Ashwini Verma
Ashwini Verma

Reputation: 7525

It's not MVC Routing where you got confused. What you need to understand is SEO friendly urls. These url("MyController/3/4") helps search engines to easily find the pages.

Have a look at these links. You'll have a better reason.

SEO Friendly URL

MVC Routing

Upvotes: 0

Related Questions