Jake Manet
Jake Manet

Reputation: 1252

MVC routing expect the Id when it sould not

I have troubles with my routing: I have in my controller this method:

[HttpGet]
public JsonResult GetCase(CustomIdentity currentUser, string objectType, Guid objectId)

And in my routes

r.Match("CTRL/{id}", "CTRL", "details");
r.Match("CTRL/GetCase", "CTRL", "GetCase");

The problem is when i want to initiate a GET to my method: I can do that only with

http://a.com/CTRL/GetCase/EE5014C2-C4AA-44E2-80F9-A23D01317790?objectType=123&objectId=1E5014C2-C4AA-44E2-80F9-A23D01317790

But i need

http://a.com/CTRL/GetCase?objectType=123&objectId=1E5014C2-C4AA-44E2-80F9-A23D01317790

What is wrong with my code?

Upvotes: 1

Views: 23

Answers (1)

Nkosi
Nkosi

Reputation: 247641

Switch the order of the route setup. The first URI...

http://a.com/CTRL/GetCase/EE5014C2-C4AA-44E2-80F9-A23D01317790?objectType=123&objectId=1E5014C2-C4AA-44E2-80F9-A23D01317790

matches the CTRL/{id} route you set up where GetCase in the URI satisfies {id} template parameter. The convention uses the first matched route it finds when mapping routes.

You need to change the order you set up the route. From what you've shown, that would be

r.Match("CTRL/GetCase", "CTRL", "GetCase");
r.Match("CTRL/{id}", "CTRL", "details");

Upvotes: 1

Related Questions