2 ms·
What you're actually asking for is that you want urls and html to be statically typed, neither of which it makes any sense to be. Your first example is a bad e
by mattmanser 10y ago
What you're actually asking for is that you want urls and html to be statically typed, neither of which it makes any sense to be.
Your first example is a bad example because you simply don't have to use that stuff, they're convenience functions for quick prototyping using the controller names. Action links are urls, that's all, and urls are strings. If it bothers you, with a tiny amount of code in a helper method you can make it all strongly typed, or use the horrific overkill that is T4MVC as suggested in another reply.
Personally I completely avoid any MVC method with 'Action' in the method name, I use [Route] attributes and use hand-crafted urls rather than the controller autogenerated stuff. These can, again, all be hidden in nice statically typed helper functions and methods. Your example of `RedirectToAction` is simply a glorified `Redirect`, but the convenience method creates the url for you.
That's the good thing, you get to choose.
As for razor, it's the equivalent of complaining about misspelling html attributes. The whole reason that they're dynamic is so we can properly add whatever attributes we want to html, just like html allows us too. If we're using angular, we can easily add ng-attributes. If we want to make up a new data-thing-whatever, it will just work. When new attributes are released, we can simply use them without having to upgrade our MVC libraries.
The whole point is that you should be able to add it arbitrarily, it's not magic strings, it's dynamic by design. It can't be statically typed.
What you're asking for would require a new update for MVC every time they released a new html spec. It would be an utter nightmare.