When looking over MVC code you will very often run into code snippets like below:
return RedirectToAction("Index");
<li>@Html.ActionLink("Books", "Index", "Books")</li>
where controller names, controller action names or view names as provided as hard-coded strings. This is a common practice, but is it a good practice? After all if you rename controller, and forget to rename one of many references you would get a run-time error, rather than much more preferred compile-time error.
You could likely alleviate that issue by adding static Name property to your BaseController, and then use code as follows (action names would be slightly more difficult to accomplish).
<li>@Html.ActionLink("Books", "Index", BooksController.Name)</li>
So is this hard-coding something that should be considered as a lesser evil (over not using MVC). Or did people developed some practices to work around it?
You’re looking for T4MVC, which generates strongly typed classes of string constants.