0
votes

Following this page : http://blogs.msdn.com/b/webdev/archive/2013/10/17/attribute-routing-in-asp-net-mvc-5.aspx

These routes are supported:

[Route("users/{id:int}")]
public ActionResult GetUserById(int id) { . . . }

[Route("users/{id?}")]
public ActionResult GetUserById(int? id) { . . . }

But it seems that optional Nullabble< int > is not supported:

[Route("users/{id:int?}")]
public ActionResult GetUserById(int? id) { . . . }

Is there a way to use this ?

1
Whats wrong with the second method in the first code block? I dont know squat about routing, but both the supported and unsupported methods use int? and the supported one is, well, supported. - D. Ben Knoble
If im totally misreading something, is it possible to do id:int? - D. Ben Knoble
@BenKnoble ; I've updated the code. - Stef Heyenrath
OP refers and optional type int? where the type could be an integer or null. I think this is a classic xy problem. Can you please explain the problem and not your desired solution? - Dalorzo
I understand that int? can be int or null; i dont see any difference in the declarations of the two methods other than the attributes. My question is, whats wrong with the one that works? - D. Ben Knoble

1 Answers

0
votes

Works fine for me. I suspect there's something else going on, as MVC5 lets you plug that in as a route, no problem, and resolves it. Now, having both routes in there won't work, but I don't think that's what you're trying to do, is it?