0

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 ?

Stef Heyenrath
  • 9,335
  • 12
  • 66
  • 121
  • 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 Sep 14 '15 at 18:53
  • If im totally misreading something, is it possible to do `id:int?` – D. Ben Knoble Sep 14 '15 at 18:53
  • @BenKnoble ; I've updated the code. – Stef Heyenrath Sep 14 '15 at 18:55
  • 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 Sep 14 '15 at 18:55
  • 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 Sep 14 '15 at 18:59
  • I can make this route, and it works fine, maybe there is some other issue you are experiencing?... `[Route("testmethod/{id:int?}")] public string TestMethod(int? id)` – Craig H Sep 15 '15 at 09:40

1 Answers1

0

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?

David T. Macknet
  • 3,112
  • 3
  • 27
  • 36