String based programming
I really don't like the coding style of using strings instead of identifiers...
For example in MVC you can redirect to another action using
However, using the string "Index" instead of the name of the method (an action typically corresponds to a method in MVC right?!) make your code harder to maintain. Renaming the method will not rename the string for example.
That is why I like to use
However, this does not work with Controller names. Because of the way routing is implemented, using the full name of the controller confuses routing and you end up with an invalid Uri.
This problem is fixed by
This package updates Mvc6 to allows the use of the
nameof() keyword in your views
For example, instead of using strings for the name of the controller and action
<a asp-controller="Home" asp-action="Index" class="navbar-brand">Index</a>
you can use
<a asp-controller="@nameof(HomeController)" asp-action="@nameof(HomeController.Index)" class="navbar-brand">Index</a>
All you need to do extra is to add a
using to your
Startup.ConfigureServices add a call to
AddNameOf after the call to
I you're interested in how this packages works, it is available on github at
Any bugs, remarks, etc... can always be sent to firstname.lastname@example.org