Consider allowing RouteDataActionConstraintAttribute on methods #676
Comments
The attribute is marked as applying to classes and methods, but currently we only look for it on classes. An attribute present on an action with the same route data key should override the value on the controller. |
I've ran this bug right now. Any news when you are going to resolve it? |
@anfomin I'm curious... what are you trying to use it for? We haven't talked/blogged about this feature much so I'm really interested to know what you're trying to use it for. This will help us prioritize/trigae |
I'm writing action with paging support and want 2 routes:
There is a controller: [Route("Path")]
public class MySuperController : Controller
{
[HttpGet, DenyPage]
public IActionResult Index()
{
return Index(1);
}
[HttpGet("Page{page:int:min(2)}")]
public IActionResult Index(int page)
{
// some code
}
} I've created public class DenyPageAttribute : RouteConstraintAttribute
{
public DenyPageAttribute(string key = "page")
: base(key, RouteKeyHandling.DenyKey)
{
}
} But Url.Action("Index", new { page = 2 }) Current result: |
Pretty cool, this is basically what the feature is for - we use it implement areas but it fits what you're doing as well. @yishaigalatzer thoughts on priority for this? it's a small item What you're trying will certainly work (assuming we complete this item), but there are also a few simple things you try as workarounds.
|
Thanks for workaround. I've done via [Route("Path")]
public class MySuperController : Controller
{
[HttpGet(Order = 1)]
public IActionResult Index()
{
return Index(1);
}
[HttpGet("Page{page:int:min(2)}")]
public IActionResult Index(int page)
{
// some code
}
} In this code I can't use named routes or another action name because it's required to create URL to the next page without knowing actions. For example, next page URL will be generated with: Url.Action(null, new { page = page + 1 }); |
Currently we're only looking for
RouteDataActionConstraintAttribute
on classes - which is needed for area support. We should consider looking at actions as well for conceptual symmetry.AreaAttribute
would still only apply to classes.The text was updated successfully, but these errors were encountered: