T4MVC / R4MVC

R4MVC is a Roslyn code generator for ASP.NET Core MVC apps that creates strongly typed helpers that eliminate the use of literal strings in many places
Apache License 2.0
157 stars 48 forks source link

[Bind(Prefix = "...")] attribute shoud rewrite route parameter names #147

Closed btihanyi closed 3 years ago

btihanyi commented 4 years ago

The [BindAttribute] is a strange but useful way to "rename" action parameter names. If its Prefix property is set, the routing system will use that name instead of the method's variable name. So if I write this:

public IActionResult Details([Bind(Prefix = "id")] productId)
{
   ...
}

Then the common "{controller=Home}/{action=Index}/{id?}" will match this action method.

I know this is not a common scenario, but I've used a lot in our MVC project, so this should be implemented in order to be able to upgrade to ASP.NET Core. For that reason, I'm going to add a pull request for this feature.

artiomchi commented 3 years ago

The PR was merged, with a couple adjustments, and will try to get a release soon